use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class ConnectionTable method removeEndpoint.
protected void removeEndpoint(DistributedMember memberID, String reason, boolean notifyDisconnect) {
if (this.closed) {
return;
}
boolean needsRemoval = false;
synchronized (this.orderedConnectionMap) {
if (this.orderedConnectionMap.get(memberID) != null)
needsRemoval = true;
}
if (!needsRemoval) {
synchronized (this.unorderedConnectionMap) {
if (this.unorderedConnectionMap.get(memberID) != null)
needsRemoval = true;
}
}
if (!needsRemoval) {
ConcurrentMap cm = this.threadConnectionMap;
if (cm != null) {
ArrayList al = (ArrayList) cm.get(memberID);
needsRemoval = al != null && al.size() > 0;
}
}
if (needsRemoval) {
InternalDistributedMember remoteAddress = null;
synchronized (this.orderedConnectionMap) {
Object c = this.orderedConnectionMap.remove(memberID);
if (c instanceof Connection) {
remoteAddress = ((Connection) c).getRemoteAddress();
}
closeCon(reason, c);
}
synchronized (this.unorderedConnectionMap) {
Object c = this.unorderedConnectionMap.remove(memberID);
if (remoteAddress == null && (c instanceof Connection)) {
remoteAddress = ((Connection) c).getRemoteAddress();
}
closeCon(reason, c);
}
{
ConcurrentMap cm = this.threadConnectionMap;
if (cm != null) {
ArrayList al = (ArrayList) cm.remove(memberID);
if (al != null) {
synchronized (al) {
for (Iterator it = al.iterator(); it.hasNext(); ) {
Object c = it.next();
if (remoteAddress == null && (c instanceof Connection)) {
remoteAddress = ((Connection) c).getRemoteAddress();
}
closeCon(reason, c);
}
al.clear();
}
}
}
}
// close any sockets that are in the process of being connected
Set toRemove = new HashSet();
synchronized (connectingSockets) {
for (Iterator it = connectingSockets.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
ConnectingSocketInfo info = (ConnectingSocketInfo) entry.getValue();
if (info.peerAddress.equals(((InternalDistributedMember) memberID).getInetAddress())) {
toRemove.add(entry.getKey());
it.remove();
}
}
}
for (Iterator it = toRemove.iterator(); it.hasNext(); ) {
Socket sock = (Socket) it.next();
try {
sock.close();
} catch (IOException e) {
if (logger.isDebugEnabled()) {
logger.debug("caught exception while trying to close connecting socket for {}", memberID, e);
}
}
}
// close any receivers
// avoid deadlock when a NIC has failed by closing connections outside
// of the receivers sync (bug 38731)
toRemove.clear();
synchronized (this.receivers) {
for (Iterator it = receivers.iterator(); it.hasNext(); ) {
Connection con = (Connection) it.next();
if (memberID.equals(con.getRemoteAddress())) {
it.remove();
toRemove.add(con);
}
}
}
for (Iterator it = toRemove.iterator(); it.hasNext(); ) {
Connection con = (Connection) it.next();
closeCon(reason, con);
}
if (notifyDisconnect) {
// for a shutdown in progress and threw this exception:
if (owner.getDM().shutdownInProgress()) {
throw new DistributedSystemDisconnectedException("Shutdown in progress", owner.getDM().getMembershipManager().getShutdownCause());
}
}
if (remoteAddress != null) {
this.socketCloser.releaseResourcesForAddress(remoteAddress.toString());
}
}
}
use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class ConnectionTable method scheduleIdleTimeout.
/** schedule an idle-connection timeout task */
private void scheduleIdleTimeout(Connection conn) {
if (conn == null) {
// fix for bug 43529
return;
}
// Set the idle timeout
if (this.owner.idleConnectionTimeout != 0) {
try {
synchronized (this) {
if (!this.closed) {
IdleConnTT task = new IdleConnTT(conn);
conn.setIdleTimeoutTask(task);
this.getIdleConnTimer().scheduleAtFixedRate(task, this.owner.idleConnectionTimeout, this.owner.idleConnectionTimeout);
}
}
} catch (IllegalStateException e) {
if (conn.isClosing()) {
// causing the task to be canceled
return;
}
logger.debug("Got an illegal state exception: {}", e.getMessage(), e);
// Unfortunately, cancelInProgress() is not set until *after*
// the shutdown message has been sent, so we need to check the
// "closeInProgress" bit instead.
owner.getCancelCriterion().checkCancelInProgress(null);
Throwable cause = owner.getShutdownCause();
if (cause == null) {
cause = e;
}
throw new DistributedSystemDisconnectedException(LocalizedStrings.ConnectionTable_THE_DISTRIBUTED_SYSTEM_IS_SHUTTING_DOWN.toLocalizedString(), cause);
}
}
}
use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class FunctionStreamingReplyMessage method toData.
@Override
public void toData(DataOutput out) throws IOException {
super.toData(out);
out.writeInt(this.msgNum);
out.writeBoolean(this.lastMsg);
out.writeInt(this.processorId);
// soubhik. fix for ticket 40670
try {
DataSerializer.writeObject(this.result, out);
} catch (Exception ex) {
if (ex instanceof CancelException) {
throw new DistributedSystemDisconnectedException(ex);
}
NotSerializableException ioEx = new NotSerializableException(this.result.getClass().getName());
ioEx.initCause(ex);
throw ioEx;
}
}
use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class GlobalTransaction method getId.
/**
* Read current {@link #DMid} and return it
*
* @return current DMid
*/
private static String getId() {
synchronized (DmidMutex) {
InternalDistributedSystem ids = InternalDistributedSystem.getAnyInstance();
if (ids == null) {
throw new DistributedSystemDisconnectedException("No distributed system");
}
if (ids == IdsForId) {
return DMid;
}
IdsForId = ids;
DM dm = ids.getDistributionManager();
DMid = dm.getId().toString();
return DMid;
}
}
use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.
@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will disconnect the DS before sending a prepare message
vm1.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof PrepareNewPersistentMemberMessage) {
DistributionMessageObserver.setInstance(null);
getSystem().disconnect();
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm0);
putAnEntry(vm0);
updateTheEntry(vm0);
try {
createPersistentRegion(vm1);
} catch (Exception e) {
if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
throw e;
}
}
closeRegion(vm0);
// This wait for VM0 to come back
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
waitForBlockedInitialization(vm1);
createPersistentRegion(vm0);
async1.getResult();
checkForEntry(vm1);
vm0.invoke(new SerializableRunnable("check for offline members") {
public void run() {
Cache cache = getCache();
DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
DiskRegion dr = region.getDiskRegion();
assertEquals(Collections.emptySet(), dr.getOfflineMembers());
assertEquals(1, dr.getOnlineMembers().size());
}
});
}
Aggregations