FileDocCategorySizeDatePackage
StubSender.javaAPI DocExample1765Thu Nov 08 00:22:56 GMT 2001com.ora.rmibook.chapter15.impl

StubSender

public class StubSender extends Object implements Runnable

Fields Summary
private ArrayList
_customers
private BaseContextImpl
_server
Constructors Summary
public StubSender(BaseContextImpl server)

       
        _server = server;
    
Methods Summary
public synchronized voidadd(java.net.Socket socket)

        _customers.add(socket);
        notifyAll();
    
private synchronized java.net.SocketgetNextSocket()

        int size = _customers.size();

        if (0 == size) {
            return null;
        }
        size--;
        Socket returnValue = (Socket) _customers.remove(size);

        return returnValue;
    
public voidrun()

        while (true) {
            sendStub();
        }
    
public voidsendStub()

        Socket nextSocket = getNextSocket();

        if (null == nextSocket) {
            waitForSocket();
            return;
        } else {
            try {
                RemoteStub stub = (RemoteStub) RemoteStub.toStub(_server);
                OutputStream output = nextSocket.getOutputStream();
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(output);

                objectOutputStream.writeObject(stub);
                objectOutputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
private synchronized voidwaitForSocket()

        if (0 == _customers.size()) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }