use of org.apache.geode.distributed.internal.InternalDistributedSystem.ReconnectListener in project geode by apache.
the class RemoteGfManagerAgent method connectToDS.
/**
* Creates a new {@link InternalDistributedSystem} connection for this agent. If one alread
* exists, it is <code>disconnected</code> and a new one is created.
*/
protected void connectToDS() {
if (!isListening()) {
return;
}
if (system != null) {
system.disconnect();
system = null;
}
Properties props = this.transport.toDSProperties();
if (this.displayName != null && this.displayName.length() > 0) {
props.setProperty("name", this.displayName);
}
this.system = (InternalDistributedSystem) InternalDistributedSystem.connectForAdmin(props);
DM dm = system.getDistributionManager();
if (dm instanceof DistributionManager) {
((DistributionManager) dm).setAgent(this);
}
synchronized (this) {
this.disconnected = false;
}
this.system.addDisconnectListener(new InternalDistributedSystem.DisconnectListener() {
@Override
public String toString() {
return LocalizedStrings.RemoteGfManagerAgent_DISCONNECT_LISTENER_FOR_0.toLocalizedString(RemoteGfManagerAgent.this);
}
public void onDisconnect(InternalDistributedSystem sys) {
// Before the disconnect handler is called, the InternalDistributedSystem has already marked
// itself for
// the disconnection. Hence the check for RemoteGfManagerAgent.this.isConnected() always
// returns false.
// Hence commenting the same.
// if(RemoteGfManagerAgent.this.isConnected()) {
boolean reconnect = sys.isReconnecting();
if (!reconnect) {
final DisconnectListener listener = RemoteGfManagerAgent.this.getDisconnectListener();
if (RemoteGfManagerAgent.this.disconnect()) {
// call
if (listener != null) {
listener.onDisconnect(sys);
}
}
}
}
});
InternalDistributedSystem.addReconnectListener(new ReconnectListener() {
public void reconnecting(InternalDistributedSystem oldsys) {
}
public void onReconnect(InternalDistributedSystem oldsys, InternalDistributedSystem newsys) {
if (logger.isDebugEnabled()) {
logger.debug("RemoteGfManagerAgent.onReconnect attempting to join new distributed system");
}
join();
}
});
synchronized (this.myMembershipListenerLock) {
this.myMembershipListener = new MyMembershipListener();
dm.addMembershipListener(this.myMembershipListener);
Set initialMembers = dm.getDistributionManagerIds();
this.myMembershipListener.addMembers(initialMembers);
if (logger.isDebugEnabled()) {
StringBuffer sb = new StringBuffer("[RemoteGfManagerAgent] ");
sb.append("Connected to DS with ");
sb.append(initialMembers.size());
sb.append(" members: ");
for (Iterator it = initialMembers.iterator(); it.hasNext(); ) {
InternalDistributedMember member = (InternalDistributedMember) it.next();
sb.append(member);
sb.append(" ");
}
this.logger.debug(sb.toString());
}
connected = true;
for (Iterator it = initialMembers.iterator(); it.hasNext(); ) {
InternalDistributedMember member = (InternalDistributedMember) it.next();
// the JoinProcess when we first start up.
try {
handleJoined(member);
} catch (OperationCancelledException ex) {
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "join cancelled by departure");
}
}
}
this.initialized = true;
}
// sync
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem.ReconnectListener in project geode by apache.
the class ReconnectDUnitTest method addReconnectListener.
void addReconnectListener() {
// reset the count for this listener
reconnectTries = 0;
LogWriterUtils.getLogWriter().info("adding reconnect listener");
ReconnectListener reconlis = new ReconnectListener() {
public void reconnecting(InternalDistributedSystem oldSys) {
LogWriterUtils.getLogWriter().info("reconnect listener invoked");
reconnectTries++;
}
public void onReconnect(InternalDistributedSystem system1, InternalDistributedSystem system2) {
}
};
InternalDistributedSystem.addReconnectListener(reconlis);
}
Aggregations