Crowd control with Java

T

Tan Thuan Seah

Hi all
I was given a task to write a crowd control system using Java. The
system is such that there are 5 number of gates which allows crowd to
enter/exit the stadium. The gates are supposed to ensure that the crowd
inside the stadium is within the limit of say 50. Once this limit is
reached, the gates will not allow anyone to enter but only exit from the
stadium. The gates will open once more if the crowd inside is <50. I am
looking around for methods to synchonize the gates. The setup of the system
is such that there is no center control. So the coordination is among the
gates.

My plan is such:
Each gate is a thread first initialized with 50/5=10 person each
After the gate has hit that limit of 10 person, it will have to 'borrow'
from other gates.

Two questions here, I was given a few methods of communication. Through
pipes, socket, RMI or mpiJava. Are there any other methods to communicate
which I had yet to be exposed to? Also, I was thinking of setting up the
gates using ring topology for network. And I am looking around for solution
to maintain commmuncation if one of the gate were to fail. Any references
would be helpful. Thanks in advance.

Thuan Seah
 
C

Chris Smith

Tan said:
I was given a task to write a crowd control system using Java. The
system is such that there are 5 number of gates which allows crowd to
enter/exit the stadium. The gates are supposed to ensure that the crowd
inside the stadium is within the limit of say 50. Once this limit is
reached, the gates will not allow anyone to enter but only exit from the
stadium. The gates will open once more if the crowd inside is <50. I am
looking around for methods to synchonize the gates. The setup of the system
is such that there is no center control. So the coordination is among the
gates.

My plan is such:
Each gate is a thread first initialized with 50/5=10 person each
After the gate has hit that limit of 10 person, it will have to 'borrow'
from other gates.
Okay.

Two questions here, I was given a few methods of communication. Through
pipes, socket, RMI or mpiJava. Are there any other methods to communicate
which I had yet to be exposed to?

There are, of course, gazillions of choices to be had. However, before
anyone can say anything, you need to be more clear. You said above that
each gate is a thread, which would imply that this whole thing is
running inside one virtual machine. Your list of communication
technologies range from within a process (pipes, at least in the Java
meaning of that term), to inter-process (MPI) to network (sockets and
RMI). Which is it?

In any case, if you're doing threads within a process, then use
synchronized methods on a shared object. If you're using multiple
processes (whether networked or not), then barring any requirements that
you didn't mention, it looks like RMI will be the easiest by far.
Also, I was thinking of setting up the
gates using ring topology for network. And I am looking around for solution
to maintain commmuncation if one of the gate were to fail. Any references
would be helpful. Thanks in advance.

Must be between processes, then. The network topology is beyond Java's
scope. If you want to work with standard Java, you'll use a TCP/IP
network (I don't know much about mpiJava, and can't comment there).

As far as redundancy, it looks like you've got a small enough domain to
just have every node be aware of all others, so that if one is down, the
node can try to "borrow" from the others instead. The actual network
wiring is another matter: just have each node get two network
interfaces, perhaps one to each neighbor or whatever, as long as there
are redundant paths to any other node.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

he setup of the system
is such that there is no center control. So the coordination is among the
gates.

You might want to shut the system down and revert to manual control in
the event of one of the gates failing to count. You certainly don't
want exit gates ever locking no matter what happens.

You could do a udp approach where each station broadcasts its state
periodically to all the others. Each maintains a global map of the
entire state. You could do some sort of checksum every once in a
while as a reality check -- cross sanity check.

You could also do it by polling. That has the advantage of
automatically detecting a dead gate.

Do you really need a processor per gate? Surely the even the tiniest
CPU could manage the entire thing, with a hot backup.
 
T

Tan Thuan Seah

So can I say that it would be a better idea to just have every gate aware of
all the other gates(i.e simply broadcast messages) rather than going through
the trouble to deal with token ring?

Thuan Seah
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top