Search in sources :

Example 1 with OperationCancelledException

use of org.apache.geode.admin.OperationCancelledException 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
}
Also used : DisconnectListener(org.apache.geode.distributed.internal.InternalDistributedSystem.DisconnectListener) DisconnectListener(org.apache.geode.distributed.internal.InternalDistributedSystem.DisconnectListener) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) OperationCancelledException(org.apache.geode.admin.OperationCancelledException) ReconnectListener(org.apache.geode.distributed.internal.InternalDistributedSystem.ReconnectListener)

Example 2 with OperationCancelledException

use of org.apache.geode.admin.OperationCancelledException in project geode by apache.

the class AdminWaiters method sendAndWait.

// private static final long TIMEOUT = 10000L;
/**
   * Sends <code>msg</code> using <code>dm</code> and waits for the response.
   * 
   * @return the response.
   * @throws RuntimeAdminException if this method is interrupted, times out, cancelled
   *         ({@link #cancelWaiters}), or failed with an exception on the server side.
   */
public static AdminResponse sendAndWait(AdminRequest msg, DistributionManager dm) {
    // we have to handle admin messages sent to ourselves specially.
    if (dm.getId().equals(msg.getRecipient())) {
        // Sent from myself
        msg.setSender(dm.getId());
        return msg.createResponse(dm);
    }
    AdminResponse result = null;
    try {
        synchronized (msg) {
            Set failures = dm.putOutgoing(msg);
            if (failures != null && failures.size() > 0) {
                // didn't go out
                if (dm.getDistributionManagerIds().contains(msg.getRecipient())) {
                    // it's still in the view
                    String s = "";
                    if (logger.isTraceEnabled(LogMarker.DM)) {
                        s += " (" + msg + ")";
                    }
                    throw new RuntimeAdminException(LocalizedStrings.AdminWaiters_COULD_NOT_SEND_REQUEST_0.toLocalizedString(s));
                }
                throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SENT_TO_0_FAILED_SINCE_MEMBER_DEPARTED_1.toLocalizedString(new Object[] { msg.getRecipient(), "" }));
            }
            // sent it
            long timeout = getWaitTimeout();
            boolean gotResponse = msg.waitForResponse(timeout);
            if (!gotResponse) {
                if (dm.isCurrentMember(msg.getRecipient())) {
                    // still here?
                    // no one ever replied
                    StringBuffer sb = new StringBuffer("Administration request ");
                    sb.append(msg);
                    sb.append(" sent to ");
                    sb.append(msg.getRecipient());
                    sb.append(" timed out after ");
                    sb.append((timeout / 1000));
                    sb.append(" seconds.");
                    throw new RuntimeAdminException(sb.toString());
                }
                // still here?
                // recipient vanished
                String s = "";
                if (logger.isTraceEnabled(LogMarker.DM)) {
                    s = " (" + msg + ")";
                }
                throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SENT_TO_0_FAILED_SINCE_MEMBER_DEPARTED_1.toLocalizedString(new Object[] { msg.getRecipient(), s }));
            }
            // !gotResponse
            result = msg.getResponse();
        }
    // synchronized
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        dm.getCancelCriterion().checkCancelInProgress(ex);
        String s = LocalizedStrings.AdminWaiters_REQUEST_WAIT_WAS_INTERRUPTED.toLocalizedString();
        if (logger.isTraceEnabled(LogMarker.DM)) {
            s += " (" + msg + ")";
        }
        throw new RuntimeAdminException(s, ex);
    }
    if (result == null) {
        String s = "";
        if (logger.isTraceEnabled(LogMarker.DM)) {
            s += " (" + msg + ")";
        }
        throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SEND_TO_0_WAS_CANCELLED_1.toLocalizedString(new Object[] { msg.getRecipient(), s }));
    } else if (result instanceof AdminFailureResponse) {
        throw new RuntimeAdminException(LocalizedStrings.AdminWaiters_REQUEST_FAILED.toLocalizedString(), ((AdminFailureResponse) result).getCause());
    }
    return result;
}
Also used : Set(java.util.Set) RuntimeAdminException(org.apache.geode.admin.RuntimeAdminException) OperationCancelledException(org.apache.geode.admin.OperationCancelledException)

Aggregations

OperationCancelledException (org.apache.geode.admin.OperationCancelledException)2 Set (java.util.Set)1 RuntimeAdminException (org.apache.geode.admin.RuntimeAdminException)1 DisconnectListener (org.apache.geode.distributed.internal.InternalDistributedSystem.DisconnectListener)1 ReconnectListener (org.apache.geode.distributed.internal.InternalDistributedSystem.ReconnectListener)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1