开发者

Addressing Scalability,Performance and Optimization issues in RMI Application?

开发者 https://www.devze.com 2023-01-20 03:47 出处:网络
my problem is: this design is working finefor one ball but i m unable to get it work for multiple balls, i have basically problem in replacing the \"this\" keyword in updateClients ().

my problem is: this design is working fine for one ball but i m unable to get it work for multiple balls, i have basically problem in replacing the "this" keyword in updateClients ().

i thought i need to do something like this but i m failed:

System.out.println("in ballimpl" + j.size());
            for (ICallback aClient : j) {
                aClient.updateClients(BallImpl[i]);
            }

The current situation of code is :

The model remote object, which is iterating client list and calling update method of them,

public class BallImpl extends UnicastRemoteObject implements Ball,Runnable {


    private List<ICallback> clients = new ArrayList<ICallback>();


    protected static ServerServices chatServer;
    static ServerServices si;

    BallImpl() throws RemoteException {
        super();
}
 ....

    public  synchronized void move() throws RemoteException {
        loc.translate((int) changeInX, (int) changeInY);
    }

    public void start() throws RemoteException {
        if (gameThread.isAlive()==false )
            if (run==false){
                  gameThread.start();

            }
    }
    /** Start the ball bouncing. */

        // Run the game logic in its own thread.

            public void run() {

                while (true) {
                    run=true;
                    // Execute one game step
                    try {
                        updateClients();
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }

                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException ex) {
                    }
                }
            }
     public void updateClients() throws RemoteException {

        si = new ServerServicesImpl();
        List<ICallback> j = si.getClientNames();
        System.out.println("in messimpl " + j.size());
        if (j != null) {
            System.out.pr开发者_JAVA百科intln("in ballimpl" + j.size());
            for (ICallback aClient : j) {
                aClient.updateClients(this);
            }

        } else
            System.err.println("Clientlist is empty");
       } 
    }

The client which is implementing callback interface and has update method implementation :

public final class thenewBallWhatIwant implements Runnable, ICallback {

.....

@Override
public void updateClients(final Ball ball) throws RemoteException {

    try {
        ball.move();
        try {
            Thread.sleep(50);
        } catch (Exception e) {
            System.exit(0);
        }
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}
 .....
}

thanks for any feedback.

jibbylala


Separate your RMI logic from your Ball logic.

You should be able to run your ball simulation without needing any RMI modules. Just to run it locally, to test it. Then you should find a way to wrap that process in RMI so that you can still run it locally to test it without any sort of RMI interface. This block of code is the engine, and it is very important to be able to test it in as atomic a form as possible. Having extra parts integrated with it just increases the complexity of what will undoubtedly be some of the most complex code.

Don't let any extra interfaces into your engine. It should be very specific and few the packages required to use your engine. Any new functionality your software needs, implement it appropriately in the engine to support generic design. Wrap that to provide specific functionality outside the core of the engine. This protects the engine design against changes to the environment. It also allows for more complete testing of the engine.

We make exceptions sometimes in cases where something will only ever be used in one way. But in this case, testing without RMI would seem to be critical to getting your engine working correctly. If your engine runs faster than the network can keep up due to large numbers of clients connecting, do you want the whole game to slow down, or do you want the clients to lag behind? I say, you want to be able to make that choice.

0

精彩评论

暂无评论...
验证码 换一张
取 消