Instantiating Servlets at runtime

A

Alex

Hi,

I am trying to build a webapp with servlets that runs several games
concurrently. I was hoping to have each seperate game run in the background
by a seperate servlet instance, where requests are forwarded to the
instances by a GameMaster servlet.

It would be possible to do this if there were a fixed number of games, by
simply naming Game1 - Game6 in web.xml, but I was hoping to let games be
created and ended on-the-fly and I don't know if this is possible.

Does anyone have any suggestions?

I probably haven't made much sense above so I will include a paragraph from
www.acknowledge.co.uk which explains what I am trying to do, but only with a
fixed number of games:

"There is one servlet instance per registered servlet name. But why? Well
say you have a servlet class that is a front end to a game called Vengance
that is played over the Internet. Vengance is a multiplayer game that can be
run in either death match mode or team match mode. The Vengance servlet uses
initialisation parameters to determine which mode the game should be played
in. Although we have one Vengance servlet class, we need two servlet
instances. We name one servlet instance DeathMatchVengance and the other
TeamMatchVengance. They are two totally different games, two totally
different servlets, that are accessed by two totally different sets of
players. In short we need two different servlets that are instantiated from
the same servlet class. We can achieve this by registering the Vengance
servlet class under two different names. Also we configure these two
Vengance servlet instances take different initialisation parameters, one for
team match mode and the other for death match mode. Hence, the reality is
one servlet instance per registered servlet name."

Thanks for your help,
Alex
 
J

Juha Laiho

"Alex" <[email protected]> said:

(people at Right Management Consultants, Philadelphia, must be happy
about your choice of fake domain name - when creating fakes, use
such that end with ".invalid", and will not become valid domain names
even with the ".invalid" removed)
I am trying to build a webapp with servlets that runs several games
concurrently. I was hoping to have each seperate game run in the background
by a seperate servlet instance, where requests are forwarded to the
instances by a GameMaster servlet.

It would be possible to do this if there were a fixed number of games, by
simply naming Game1 - Game6 in web.xml, but I was hoping to let games be
created and ended on-the-fly and I don't know if this is possible.

Does anyone have any suggestions?

Write your game first so that it isn't dependent on servlets. Just
create some interface through which commands can be entered; this
interface should also handle the issues of distinguishing several games.
You'll anyway have to store the game situation data somewhere (in a
database?), so design your data store in such a way that it'll be easy
to add/remove instances of game data.

After that, write a servlet frontend through which commands can be
entered. This servlet frontend will apparently need some data storage
of its own, for maintaining the player/game data.
 
A

Alex

Juha Laiho said:
"Alex" <[email protected]> said:

(people at Right Management Consultants, Philadelphia, must be happy
about your choice of fake domain name - when creating fakes, use
such that end with ".invalid", and will not become valid domain names
even with the ".invalid" removed)

Point taken :p
Write your game first so that it isn't dependent on servlets. Just
create some interface through which commands can be entered; this
interface should also handle the issues of distinguishing several games.
You'll anyway have to store the game situation data somewhere (in a
database?), so design your data store in such a way that it'll be easy
to add/remove instances of game data.

After that, write a servlet frontend through which commands can be
entered. This servlet frontend will apparently need some data storage
of its own, for maintaining the player/game data.

If the games are not servlets then it would become quite difficult to make
them render pages. I would have to pass all the reqest, response, context,
session, printwriter etc. objects to each one; or am I making this far more
complicated than it should be?

Thank you from you help

Alex
 
J

Juha Laiho

Alex said:
If the games are not servlets then it would become quite difficult to make
them render pages. I would have to pass all the reqest, response, context,
session, printwriter etc. objects to each one; or am I making this far more
complicated than it should be?

I think you're seeing this more complex than it needs.

From the perspective of the game engine, the way to get the commands and
to display the output should have very little effect. So, plainly in the
context of your game, think what is the input the game engine needs
(and what is the context that needs to be maintained somewhere outside
the game engine to store the "game world"). Arrange for the input layer
to be able to provide the needed data, and some way to identify the
context to which this input data is related.

Similarly, the display code shouldn't need the game logic - it just needs
to somehow get the information on what to display. Think on what data is
needed to present the display to the user - and provide the display layer
some way to get to that data. Espeially as you're thinking of a web-based
solution, you pretty much have to create each new display from scratch;
you cannot just "clear a character/pixel from position p, and show
a charaxter/pixel at position p2".
 
K

kjc

Alex said:
Hi,

I am trying to build a webapp with servlets that runs several games
concurrently. I was hoping to have each seperate game run in the background
by a seperate servlet instance, where requests are forwarded to the
instances by a GameMaster servlet.

It would be possible to do this if there were a fixed number of games, by
simply naming Game1 - Game6 in web.xml, but I was hoping to let games be
created and ended on-the-fly and I don't know if this is possible.

Does anyone have any suggestions?

I probably haven't made much sense above so I will include a paragraph from
www.acknowledge.co.uk which explains what I am trying to do, but only with a
fixed number of games:

"There is one servlet instance per registered servlet name. But why? Well
say you have a servlet class that is a front end to a game called Vengance
that is played over the Internet. Vengance is a multiplayer game that can be
run in either death match mode or team match mode. The Vengance servlet uses
initialisation parameters to determine which mode the game should be played
in. Although we have one Vengance servlet class, we need two servlet
instances. We name one servlet instance DeathMatchVengance and the other
TeamMatchVengance. They are two totally different games, two totally
different servlets, that are accessed by two totally different sets of
players. In short we need two different servlets that are instantiated from
the same servlet class. We can achieve this by registering the Vengance
servlet class under two different names. Also we configure these two
Vengance servlet instances take different initialisation parameters, one for
team match mode and the other for death match mode. Hence, the reality is
one servlet instance per registered servlet name."

Thanks for your help,
Alex
Wrong model.
Use an applet.
 
A

Alex

Juha Laiho said:
From the perspective of the game engine, the way to get the commands and
to display the output should have very little effect. So, plainly in the
context of your game, think what is the input the game engine needs
(and what is the context that needs to be maintained somewhere outside
the game engine to store the "game world"). Arrange for the input layer
to be able to provide the needed data, and some way to identify the
context to which this input data is related.

Similarly, the display code shouldn't need the game logic - it just needs
to somehow get the information on what to display. Think on what data is
needed to present the display to the user - and provide the display layer
some way to get to that data. Espeially as you're thinking of a web-based
solution, you pretty much have to create each new display from scratch;
you cannot just "clear a character/pixel from position p, and show
a charaxter/pixel at position p2".

I think I see what you mean: I need a servlet to handle the user input
which interprets it and call the appropriate commands in the correct game
engine instance. The engine updates a 'game state' stored somewhere and the
orginal (or perhaps a different) servlet interprets the game state and
simply 'draws' it.

Thank you.
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top