use of org.apache.geode.distributed.internal.InternalDistributedSystem.DisconnectListener in project geode by apache.
the class InternalLocator method startDistributedSystem.
/**
* Start a distributed system whose life cycle is managed by this locator. When the locator is
* stopped, this distributed system will be disconnected. If a distributed system already exists,
* this method will have no affect.
*
* @since GemFire 5.7
*/
private void startDistributedSystem() throws UnknownHostException {
InternalDistributedSystem existing = InternalDistributedSystem.getConnectedInstance();
if (existing != null) {
// LOG: changed from config to info
logger.info(LocalizedMessage.create(LocalizedStrings.InternalLocator_USING_EXISTING_DISTRIBUTED_SYSTEM__0, existing));
startCache(existing);
} else {
StringBuilder sb = new StringBuilder(100);
if (this.bindAddress != null) {
sb.append(this.bindAddress.getHostAddress());
} else {
sb.append(SocketCreator.getLocalHost().getHostAddress());
}
sb.append('[').append(getPort()).append(']');
String thisLocator = sb.toString();
if (this.peerLocator) {
// append this locator to the locators list from the config properties
// this.logger.config("ensuring that this locator is in the locators list");
boolean setLocatorsProp = false;
String locatorsProp = this.config.getLocators();
if (StringUtils.isNotBlank(locatorsProp)) {
if (!locatorsProp.contains(thisLocator)) {
locatorsProp = locatorsProp + ',' + thisLocator;
setLocatorsProp = true;
}
} else {
locatorsProp = thisLocator;
setLocatorsProp = true;
}
if (setLocatorsProp) {
Properties updateEnv = new Properties();
updateEnv.setProperty(LOCATORS, locatorsProp);
this.config.setApiProps(updateEnv);
// fix for bug 41248
String propName = DistributionConfig.GEMFIRE_PREFIX + LOCATORS;
if (System.getProperty(propName) != null) {
System.setProperty(propName, locatorsProp);
}
}
// No longer default mcast-port to zero. See 46277.
}
Properties connectEnv = new Properties();
// LogWriterAppender is now shared via that class
// using a DistributionConfig earlier in this method
connectEnv.put(DistributionConfig.DS_CONFIG_NAME, this.config);
logger.info(LocalizedMessage.create(LocalizedStrings.InternalLocator_STARTING_DISTRIBUTED_SYSTEM));
// LOG:CONFIG: changed from config to info
logger.info(LogMarker.CONFIG, LocalizedMessage.create(LocalizedStrings.InternalDistributedSystem_STARTUP_CONFIGURATIONN_0, this.config.toLoggerString()));
this.myDs = (InternalDistributedSystem) DistributedSystem.connect(connectEnv);
if (this.peerLocator) {
this.locatorImpl.setMembershipManager(this.myDs.getDM().getMembershipManager());
}
this.myDs.addDisconnectListener(new DisconnectListener() {
@Override
public void onDisconnect(InternalDistributedSystem sys) {
stop(false, false, false);
}
});
startCache(myDs);
logger.info(LocalizedMessage.create(LocalizedStrings.InternalLocator_LOCATOR_STARTED_ON__0, thisLocator));
myDs.setDependentLocator(this);
}
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem.DisconnectListener 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
}
Aggregations