Dear Experts,
i am stuck in a situation, where i need to move balls in multi-user way, i m using RMI in a distributed animation of moving BALLS .
My goal is to move multiple balls in a way, so that multiple clients observe the same movement/position of balls, i m using ball object which is remote object.
My problem is: i am calling the move function, which is remote and increasing no of clients causes calling that function more frequently and it causes ball speed more and more because of increasing no of calls to this method from different clients.
can somebody please recommend me that how could i cope with this problem that when ball is already moving on one client then other ball don't call the function but just utilize that.
here is code :
public void start() {
Play = true;
Thread t = new Thread(this);
t.start();
}
public void run() {
while (Play == true) {
runball();
pit.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ie) {
stop();
}
}
}
public void runball() {
try {
aBall.setBounds(pit.getWidth(), pit.getHeight());
aBall.move();
}
catch (Exception e) {
e.printStackTrace();
}
}
and there is my remote move method:
public void move() throws RemoteException {
// ... Move the ball at the give velocity.
m_x += m_velocityX;
m_y += m_velocityY;
if (m_x < 0) { // If at or beyond left side
m_x = 0; // Place against edge and
m_velocityX = -m_velocityX;
} else if (m_x > m_rightBound) { // If at or beyond right side
m_x = m_rightBound; // Place against right edge.
m_velocityX = -m_velocityX;
}
if (m_y < 0) { // if we're at top
m_y = 1;
m_velocityY = -m_velocityY;
} else if (m_y > m_bottomBound) { // if we're at bottom
m_y = m_bottomBound;
m_velocityY = -m_velocityY;
}
}
Can somebody please guide me , there is some problem in this design and i m using the RMI in wrong way? or recommend me some design by which i can accomplish my goal.
thanks a lot,
jibby