org.wings.comet.RMICometConnectionManager Maven / Gradle / Ivy
The newest version!
package org.wings.comet;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;
class RMICometConnectionManager extends CometConnectionManager {
private RemoteConnectionSet connectionSet;
public RMICometConnectionManager() {
connectionSet = getSharedObject();
}
@Override
public boolean canAddHangingGet() {
synchronized (connectionSet) {
try {
return !connectionSet.contains(getBrowserId());
} catch (RemoteException e) {
//e.printStackTrace();
connectionSet = getSharedObject();
return canAddHangingGet();
}
}
}
@Override
public boolean addHangingGet() {
synchronized (connectionSet) {
try {
final boolean result = !connectionSet.contains(getBrowserId());
connectionSet.add(getBrowserId());
return result;
} catch (RemoteException e) {
//e.printStackTrace();
connectionSet = getSharedObject();
return addHangingGet();
}
}
}
@Override
public void removeHangingGet() {
synchronized (connectionSet) {
try {
connectionSet.remove(getBrowserId());
} catch (RemoteException e) {
//e.printStackTrace();
connectionSet = getSharedObject();
removeHangingGet();
}
}
}
static RemoteConnectionSet getSharedObject() {
RemoteConnectionSet remoteConnectionSet = null;
try {
Registry registry = LocateRegistry.getRegistry();
remoteConnectionSet = (RemoteConnectionSet) registry.lookup(NAME);
} catch (RemoteException e) {
//e.printStackTrace();
remoteConnectionSet = new ConnectionSet();
} catch (NotBoundException e) {
e.printStackTrace();
}
return remoteConnectionSet;
}
}