use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class ClientSOContainer method handleViewChangeMessage.
protected void handleViewChangeMessage(ContainerMessage mess) throws IOException {
if (!isConnected())
return;
final ContainerMessage.ViewChangeMessage vc = (ContainerMessage.ViewChangeMessage) mess.getData();
if (vc == null)
// $NON-NLS-1$
throw new IOException("view change message cannot be null");
final ID fromID = mess.getFromContainerID();
if (fromID == null || !fromID.equals(remoteServerID)) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new IOException("view change message fromID=" + fromID + " is not from remoteServerID=" + remoteServerID);
}
final ID[] changeIDs = vc.getChangeIDs();
if (changeIDs == null) {
// do nothing if we've got no changes
} else {
for (int i = 0; i < changeIDs.length; i++) {
if (vc.isAdd()) {
boolean wasAdded = false;
synchronized (getGroupMembershipLock()) {
// known
if (groupManager.getMemberForID(changeIDs[i]) == null) {
wasAdded = true;
groupManager.addMember(new Member(changeIDs[i]));
}
}
// accomplished
if (wasAdded)
fireContainerEvent(new ContainerConnectedEvent(getID(), changeIDs[i]));
} else {
if (changeIDs[i].equals(getID())) {
// We've been ejected.
final ID serverID = remoteServerID;
synchronized (getGroupMembershipLock()) {
handleLeave(remoteServerID, connection);
}
// Notify listeners that we've been ejected
fireContainerEvent(new ContainerEjectedEvent(getID(), serverID, vc.getData()));
} else {
synchronized (getGroupMembershipLock()) {
groupManager.removeMember(changeIDs[i]);
}
// Notify listeners that another remote has gone away
fireContainerEvent(new ContainerDisconnectedEvent(getID(), changeIDs[i]));
}
}
}
}
}
use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class ClientSOContainer method connect.
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.generic.SOContainer#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
*/
public void connect(ID targetID, IConnectContext joinContext) throws ContainerConnectException {
try {
if (isClosing)
// $NON-NLS-1$
throw new IllegalStateException("Container closing");
if (targetID == null)
// $NON-NLS-1$
throw new ContainerConnectException("targetID cannot be null");
Object response = null;
synchronized (getConnectLock()) {
// Throw if already connected
if (isConnected())
// $NON-NLS-1$
throw new IllegalStateException("Container already connected connectedID=" + getConnectedID());
// Throw if connecting
if (isConnecting())
// $NON-NLS-1$
throw new IllegalStateException("Container connecting");
// else we're entering connecting state
// first notify synchonously
final ISynchAsynchConnection aConnection = createConnection(targetID, joinContext);
setStateConnecting(aConnection);
fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, joinContext));
final Object connectData = getConnectData(targetID, joinContext);
final int connectTimeout = getConnectTimeout();
synchronized (aConnection) {
try {
// Make connect call
response = aConnection.connect(targetID, connectData, connectTimeout);
} catch (final ECFException e) {
if (getConnection() != aConnection)
disconnect(aConnection);
else
setStateDisconnected(aConnection);
throw e;
}
// If not in correct state, disconnect and return
if (getConnection() != aConnection) {
disconnect(aConnection);
// $NON-NLS-1$
throw new IllegalStateException("Container connect failed because not in correct state");
}
ID serverID = null;
try {
serverID = handleConnectResponse(targetID, response);
} catch (final Exception e) {
setStateDisconnected(aConnection);
throw e;
}
setStateConnected(serverID, aConnection);
// notify listeners
fireContainerEvent(new ContainerConnectedEvent(this.getID(), remoteServerID));
aConnection.start();
}
}
} catch (final ContainerConnectException e) {
throw e;
} catch (final ECFException e) {
final IStatus s = e.getStatus();
throw new ContainerConnectException(s.getMessage(), s.getException());
} catch (final Exception e) {
throw new ContainerConnectException(e.getLocalizedMessage(), e);
}
}
use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class ClientApplication method createClient.
protected ISharedObjectContainer createClient() throws Exception {
// Make identity instance for the new container
ID newContainerID = IDFactory.getDefault().createGUID();
ISharedObjectContainer result = SharedObjectContainerFactory.getDefault().createSharedObjectContainer(contd, new Object[] { newContainerID, new Integer(DEFAULT_TIMEOUT) });
return result;
}
use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class ClientApplication method main.
/**
* An ECF client container implementation that runs as an application.
* <p>
* Usage: java org.eclipse.ecf.provider.app.ClientApplication
* <serverid>
* <p>
* If <serverid> is omitted or "-" is specified,
* ecftcp://localhost:3282/server" is used.
*/
public static void main(String[] args) throws Exception {
ClientApplication st = new ClientApplication();
st.init(args);
// Get server id to join
ID serverID = IDFactory.getDefault().createStringID(st.serverName);
st.connect(serverID);
st.createSharedObjects();
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("Waiting " + DEFAULT_WAITTIME + " ms...");
Thread.sleep(DEFAULT_WAITTIME);
st.removeSharedObjects();
st.disconnect();
// $NON-NLS-1$
System.out.println("Exiting.");
}
use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class RemoteServiceRegistrationImpl method publish.
public void publish(RemoteServiceRegistryImpl registry, Object svc, String[] clzzes, Dictionary props) {
this.service = svc;
this.clazzes = clzzes;
this.reference = new RemoteServiceReferenceImpl(this);
synchronized (registry) {
ID containerID = registry.getContainerID();
if (containerID == null)
// $NON-NLS-1$
throw new NullPointerException("Local containerID must be non-null to register remote services");
this.remoteServiceID = registry.createRemoteServiceID(registry.getNextServiceId());
this.properties = createProperties(props);
registry.publishService(this);
}
}
Aggregations