背景: 我帮助开发一种多人游戏,主要用C++编写,使用标准的客户端 - 服务器架构.服务器可以自己编译,客户端与服务器一起编译,因此您可以托管游戏.
问题
游戏将客户端和服务器代码组合到同一个类中,这开始变得非常麻烦.
例如,以下是您在公共类中可能看到的一些小样本:
// Server + client
Point Ship::calcPosition()
{
// Do position calculations; actual (server) and predictive (client)
}
// Server only
void Ship::explode()
{
// Communicate to the client that this ship has died
}
// Client only
#ifndef SERVER_ONLY
void Ship::renderExplosion()
{
// Renders explosion graphics and sound effects
}
#endif
Run Code Online (Sandbox Code Playgroud)
标题:
class Ship
{
// Server + client
Point calcPosition();
// Server only
void explode();
// Client only
#ifndef SERVER_ONLY
void renderExplosion(); …Run Code Online (Sandbox Code Playgroud) 为了统一Websphere 7和GlassFish 3环境中的部署,我决定尝试在GlassFish中实现CommonJ WorkManager和TimerManager.但它没有按预期工作.我做了以下事情:
使用在http://commonj.myfoo.de/上找到的myFOO CommonJ实现,并将库包含到我的domain/lib文件夹中(包括Spring库)
将以下内容添加到<resources>glassfish domain.xml 的部分:
<custom-resource res-type="commonj.work.WorkManager" jndi-name="wm/default" factory-class="de.myfoo.commonj.work.FooWorkManagerFactory"></custom-resource>
<custom-resource res-type="commonj.timers.TimerManager" jndi-name="tm/default" factory-class="de.myfoo.commonj.timers.FooTimerManagerFactory"></custom-resource>
Run Code Online (Sandbox Code Playgroud)
在domain.xml 的<servers>/ <server>section中包含引用:
<resource-ref ref="wm/default"></resource-ref>
<resource-ref ref="tm/default"></resource-ref>
Run Code Online (Sandbox Code Playgroud)
在我的测试应用程序的web.xml中添加适当的资源引用:
<resource-ref>
<description>WorkManager</description>
<res-ref-name>wm/default</res-ref-name>
<res-type>commonj.work.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<description>TimerManager</description>
<res-ref-name>tm/default</res-ref-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)
将以下bean添加到我的applicationContext.xml:
<bean id="threadTestTaskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName" value="wm/default" />
<property name="resourceRef" value="true"/>
</bean>
<bean id="threadTestTimerExecutor" class="org.springframework.scheduling.commonj.TimerManagerTaskScheduler">
<property name="timerManagerName" value="tm/default" />
<property name="resourceRef" value="true" />
<property name="shared" value="false" />
</bean>
<bean id="threadTest" class="test.ThreadTester"></bean>
<task:scheduled-tasks scheduler="threadTestTimerExecutor">
<task:scheduled …Run Code Online (Sandbox Code Playgroud)