Search in sources :

Example 6 with UpdateAttributesProcessor

use of org.apache.geode.internal.cache.UpdateAttributesProcessor in project geode by apache.

the class GatewaySenderEventRemoteDispatcher method initializeConnection.

/**
   * Initializes the <code>Connection</code>.
   *
   * @throws GatewaySenderException
   */
private void initializeConnection() throws GatewaySenderException, GemFireSecurityException {
    this.connectionLifeCycleLock.writeLock().lock();
    try {
        // Attempt to acquire a connection
        if (this.sender.getProxy() == null || this.sender.getProxy().isDestroyed()) {
            this.sender.initProxy();
        } else {
            this.processor.resetBatchId();
        }
        Connection con;
        try {
            if (this.sender.isParallel()) {
                /*
           * TODO - The use of acquireConnection should be removed from the gateway code. This
           * method is fine for tests, but these connections should really be managed inside the
           * pool code. If the gateway needs to persistent connection to a single server, which
           * should create have the OpExecutor that holds a reference to the connection (similar to
           * the way we do with thread local connections). Use {@link
           * ExecutablePool#setupServerAffinity(boolean)} for gateway code
           */
                con = this.sender.getProxy().acquireConnection();
                // For parallel sender, setting server location will not matter.
                // everytime it will ask for acquire connection whenever it needs it. I
                // am saving this server location for command purpose
                sender.setServerLocation(con.getServer());
            } else {
                synchronized (this.sender.getLockForConcurrentDispatcher()) {
                    ServerLocation server = this.sender.getServerLocation();
                    if (server != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("ServerLocation is: {}. Connecting to this serverLocation...", server);
                        }
                        con = this.sender.getProxy().acquireConnection(server);
                    } else {
                        if (logger.isDebugEnabled()) {
                            logger.debug("ServerLocation is null. Creating new connection. ");
                        }
                        con = this.sender.getProxy().acquireConnection();
                        // PRIMARY
                        if (this.sender.isPrimary()) {
                            if (sender.getServerLocation() == null) {
                                sender.setServerLocation(con.getServer());
                            }
                            new UpdateAttributesProcessor(this.sender).distribute(false);
                        }
                    }
                }
            }
        } catch (ServerConnectivityException e) {
            this.failedConnectCount++;
            Throwable ex = null;
            if (e.getCause() instanceof GemFireSecurityException) {
                ex = e.getCause();
                if (logConnectionFailure()) {
                    // only log this message once; another msg is logged once we connect
                    logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_COULD_NOT_CONNECT_1, new Object[] { this.processor.getSender().getId(), ex.getMessage() }));
                }
                throw new GatewaySenderException(ex);
            }
            List<ServerLocation> servers = this.sender.getProxy().getCurrentServers();
            String ioMsg = null;
            if (servers.size() == 0) {
                ioMsg = LocalizedStrings.GatewayEventRemoteDispatcher_THERE_ARE_NO_ACTIVE_SERVERS.toLocalizedString();
            } else {
                final StringBuilder buffer = new StringBuilder();
                for (ServerLocation server : servers) {
                    String endpointName = String.valueOf(server);
                    if (buffer.length() > 0) {
                        buffer.append(", ");
                    }
                    buffer.append(endpointName);
                }
                ioMsg = LocalizedStrings.GatewayEventRemoteDispatcher_NO_AVAILABLE_CONNECTION_WAS_FOUND_BUT_THE_FOLLOWING_ACTIVE_SERVERS_EXIST_0.toLocalizedString(buffer.toString());
            }
            ex = new IOException(ioMsg);
            // Set the serverLocation to null so that a new connection can be
            // obtained in next attempt
            this.sender.setServerLocation(null);
            if (this.failedConnectCount == 1) {
                // only log this message once; another msg is logged once we connect
                logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT, this.processor.getSender().getId()));
            }
            // same as the other exceptions that might occur in sendBatch.
            throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT.toLocalizedString(this.processor.getSender().getId()), ex);
        }
        if (this.failedConnectCount > 0) {
            Object[] logArgs = new Object[] { this.processor.getSender().getId(), con, Integer.valueOf(this.failedConnectCount) };
            logger.info(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_USING_1_AFTER_2_FAILED_CONNECT_ATTEMPTS, logArgs));
            this.failedConnectCount = 0;
        } else {
            Object[] logArgs = new Object[] { this.processor.getSender().getId(), con };
            logger.info(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_USING_1, logArgs));
        }
        this.connection = con;
        this.processor.checkIfPdxNeedsResend(this.connection.getQueueStatus().getPdxSize());
    } catch (ConnectionDestroyedException e) {
        throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT.toLocalizedString(this.processor.getSender().getId()), e);
    } finally {
        this.connectionLifeCycleLock.writeLock().unlock();
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) Connection(org.apache.geode.cache.client.internal.Connection) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) UpdateAttributesProcessor(org.apache.geode.internal.cache.UpdateAttributesProcessor) List(java.util.List) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)

Example 7 with UpdateAttributesProcessor

use of org.apache.geode.internal.cache.UpdateAttributesProcessor in project geode by apache.

the class ParallelGatewaySenderImpl method start.

@Override
public void start() {
    this.getLifeCycleLock().writeLock().lock();
    try {
        if (isRunning()) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.GatewaySender_SENDER_0_IS_ALREADY_RUNNING, this.getId()));
            return;
        }
        if (this.remoteDSId != DEFAULT_DISTRIBUTED_SYSTEM_ID) {
            String locators = this.cache.getInternalDistributedSystem().getConfig().getLocators();
            if (locators.length() == 0) {
                throw new IllegalStateException(LocalizedStrings.AbstractGatewaySender_LOCATOR_SHOULD_BE_CONFIGURED_BEFORE_STARTING_GATEWAY_SENDER.toLocalizedString());
            }
        }
        /*
       * Now onwards all processing will happen through
       * "ConcurrentParallelGatewaySenderEventProcessor" we have made
       * "ParallelGatewaySenderEventProcessor" and "ParallelGatewaySenderQueue" as a utility classes
       * of Concurrent version of processor and queue.
       */
        eventProcessor = new RemoteConcurrentParallelGatewaySenderEventProcessor(this);
        eventProcessor.start();
        waitForRunningStatus();
        // Only notify the type registry if this is a WAN gateway queue
        if (!isAsyncEventQueue()) {
            getCache().getPdxRegistry().gatewaySenderStarted(this);
        }
        new UpdateAttributesProcessor(this).distribute(false);
        InternalDistributedSystem system = this.cache.getInternalDistributedSystem();
        system.handleResourceEvent(ResourceEvent.GATEWAYSENDER_START, this);
        logger.info(LocalizedMessage.create(LocalizedStrings.ParallelGatewaySenderImpl_STARTED__0, this));
        enqueueTempEvents();
    } finally {
        this.getLifeCycleLock().writeLock().unlock();
    }
}
Also used : UpdateAttributesProcessor(org.apache.geode.internal.cache.UpdateAttributesProcessor) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 8 with UpdateAttributesProcessor

use of org.apache.geode.internal.cache.UpdateAttributesProcessor in project geode by apache.

the class ParallelAsyncEventQueueImpl method start.

@Override
public void start() {
    this.getLifeCycleLock().writeLock().lock();
    try {
        if (isRunning()) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.GatewaySender_SENDER_0_IS_ALREADY_RUNNING, this.getId()));
            return;
        }
        if (this.remoteDSId != DEFAULT_DISTRIBUTED_SYSTEM_ID) {
            String locators = this.cache.getInternalDistributedSystem().getConfig().getLocators();
            if (locators.length() == 0) {
                throw new IllegalStateException(LocalizedStrings.AbstractGatewaySender_LOCATOR_SHOULD_BE_CONFIGURED_BEFORE_STARTING_GATEWAY_SENDER.toLocalizedString());
            }
        }
        /*
       * Now onwards all processing will happen through
       * "ConcurrentParallelGatewaySenderEventProcessor" we have made
       * "ParallelGatewaySenderEventProcessor" and "ParallelGatewaySenderQueue" as a utility classes
       * of Concurrent version of processor and queue.
       */
        eventProcessor = new ConcurrentParallelGatewaySenderEventProcessor(this);
        eventProcessor.start();
        waitForRunningStatus();
        // Only notify the type registry if this is a WAN gateway queue
        if (!isAsyncEventQueue()) {
            getCache().getPdxRegistry().gatewaySenderStarted(this);
        }
        new UpdateAttributesProcessor(this).distribute(false);
        InternalDistributedSystem system = (InternalDistributedSystem) this.cache.getDistributedSystem();
        system.handleResourceEvent(ResourceEvent.GATEWAYSENDER_START, this);
        logger.info(LocalizedMessage.create(LocalizedStrings.ParallelGatewaySenderImpl_STARTED__0, this));
        enqueueTempEvents();
    } finally {
        this.getLifeCycleLock().writeLock().unlock();
    }
}
Also used : UpdateAttributesProcessor(org.apache.geode.internal.cache.UpdateAttributesProcessor) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConcurrentParallelGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderEventProcessor)

Example 9 with UpdateAttributesProcessor

use of org.apache.geode.internal.cache.UpdateAttributesProcessor in project geode by apache.

the class SerialAsyncEventQueueImpl method start.

@Override
public void start() {
    if (logger.isDebugEnabled()) {
        logger.debug("Starting gatewaySender : {}", this);
    }
    this.getLifeCycleLock().writeLock().lock();
    try {
        if (isRunning()) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.GatewaySender_SENDER_0_IS_ALREADY_RUNNING, this.getId()));
            return;
        }
        if (this.remoteDSId != DEFAULT_DISTRIBUTED_SYSTEM_ID) {
            String locators = this.cache.getInternalDistributedSystem().getConfig().getLocators();
            if (locators.length() == 0) {
                throw new GatewaySenderConfigurationException(LocalizedStrings.AbstractGatewaySender_LOCATOR_SHOULD_BE_CONFIGURED_BEFORE_STARTING_GATEWAY_SENDER.toLocalizedString());
            }
        }
        getSenderAdvisor().initDLockService();
        if (!isPrimary()) {
            if (getSenderAdvisor().volunteerForPrimary()) {
                getSenderAdvisor().makePrimary();
            } else {
                getSenderAdvisor().makeSecondary();
            }
        }
        if (getDispatcherThreads() > 1) {
            eventProcessor = new ConcurrentSerialGatewaySenderEventProcessor(SerialAsyncEventQueueImpl.this);
        } else {
            eventProcessor = new SerialGatewaySenderEventProcessor(SerialAsyncEventQueueImpl.this, getId());
        }
        eventProcessor.start();
        waitForRunningStatus();
        this.startTime = System.currentTimeMillis();
        // Only notify the type registry if this is a WAN gateway queue
        if (!isAsyncEventQueue()) {
            getCache().getPdxRegistry().gatewaySenderStarted(this);
        }
        new UpdateAttributesProcessor(this).distribute(false);
        InternalDistributedSystem system = (InternalDistributedSystem) this.cache.getDistributedSystem();
        system.handleResourceEvent(ResourceEvent.GATEWAYSENDER_START, this);
        logger.info(LocalizedMessage.create(LocalizedStrings.SerialGatewaySenderImpl_STARTED__0, this));
        enqueueTempEvents();
    } finally {
        this.getLifeCycleLock().writeLock().unlock();
    }
}
Also used : GatewaySenderConfigurationException(org.apache.geode.internal.cache.wan.GatewaySenderConfigurationException) UpdateAttributesProcessor(org.apache.geode.internal.cache.UpdateAttributesProcessor) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConcurrentSerialGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.serial.ConcurrentSerialGatewaySenderEventProcessor) ConcurrentSerialGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.serial.ConcurrentSerialGatewaySenderEventProcessor) SerialGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.serial.SerialGatewaySenderEventProcessor)

Example 10 with UpdateAttributesProcessor

use of org.apache.geode.internal.cache.UpdateAttributesProcessor in project geode by apache.

the class GatewaySenderAdvisor method makePrimary.

public void makePrimary() {
    logger.info(LocalizedMessage.create(LocalizedStrings.SerialGatewaySenderImpl_0__STARTING_AS_PRIMARY, this.sender));
    AbstractGatewaySenderEventProcessor eventProcessor = this.sender.getEventProcessor();
    if (eventProcessor != null) {
        eventProcessor.removeCacheListener();
    }
    logger.info(LocalizedMessage.create(LocalizedStrings.SerialGatewaySenderImpl_0__BECOMING_PRIMARY_GATEWAYSENDER, this.sender));
    notifyAndBecomePrimary();
    new UpdateAttributesProcessor(this.sender).distribute(false);
}
Also used : UpdateAttributesProcessor(org.apache.geode.internal.cache.UpdateAttributesProcessor)

Aggregations

UpdateAttributesProcessor (org.apache.geode.internal.cache.UpdateAttributesProcessor)12 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)6 AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)2 RegionQueue (org.apache.geode.internal.cache.RegionQueue)2 AbstractGatewaySenderEventProcessor (org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor)2 GatewaySenderConfigurationException (org.apache.geode.internal.cache.wan.GatewaySenderConfigurationException)2 IOException (java.io.IOException)1 List (java.util.List)1 CancelException (org.apache.geode.CancelException)1 GemFireIOException (org.apache.geode.GemFireIOException)1 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)1 Connection (org.apache.geode.cache.client.internal.Connection)1 ConnectionDestroyedException (org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)1 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)1 ConcurrentParallelGatewaySenderEventProcessor (org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderEventProcessor)1 ConcurrentSerialGatewaySenderEventProcessor (org.apache.geode.internal.cache.wan.serial.ConcurrentSerialGatewaySenderEventProcessor)1 SerialGatewaySenderEventProcessor (org.apache.geode.internal.cache.wan.serial.SerialGatewaySenderEventProcessor)1 SerialGatewaySenderQueue (org.apache.geode.internal.cache.wan.serial.SerialGatewaySenderQueue)1 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)1