Search in sources :

Example 1 with IAsyncCallback

use of org.apache.cassandra.net.IAsyncCallback in project cassandra by apache.

the class MigrationTask method runMayThrow.

public void runMayThrow() throws Exception {
    // a higher major.
    if (!MigrationManager.shouldPullSchemaFrom(endpoint)) {
        logger.info("Skipped sending a migration request: node {} has a higher major version now.", endpoint);
        return;
    }
    if (!FailureDetector.instance.isAlive(endpoint)) {
        logger.debug("Can't send schema pull request: node {} is down.", endpoint);
        return;
    }
    MessageOut message = new MessageOut<>(MessagingService.Verb.MIGRATION_REQUEST, null, MigrationManager.MigrationsSerializer.instance);
    final CountDownLatch completionLatch = new CountDownLatch(1);
    IAsyncCallback<Collection<Mutation>> cb = new IAsyncCallback<Collection<Mutation>>() {

        @Override
        public void response(MessageIn<Collection<Mutation>> message) {
            try {
                Schema.instance.mergeAndAnnounceVersion(message.payload);
            } catch (ConfigurationException e) {
                logger.error("Configuration exception merging remote schema", e);
            } finally {
                completionLatch.countDown();
            }
        }

        public boolean isLatencyForSnitch() {
            return false;
        }
    };
    // Only save the latches if we need bootstrap or are bootstrapping
    if (monitoringBootstrapStates.contains(SystemKeyspace.getBootstrapState()))
        inflightTasks.offer(completionLatch);
    MessagingService.instance().sendRR(message, endpoint, cb);
}
Also used : MessageIn(org.apache.cassandra.net.MessageIn) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Collection(java.util.Collection) Mutation(org.apache.cassandra.db.Mutation) MessageOut(org.apache.cassandra.net.MessageOut) CountDownLatch(java.util.concurrent.CountDownLatch) IAsyncCallback(org.apache.cassandra.net.IAsyncCallback)

Example 2 with IAsyncCallback

use of org.apache.cassandra.net.IAsyncCallback in project cassandra by apache.

the class Gossiper method markAlive.

private void markAlive(final InetAddress addr, final EndpointState localState) {
    localState.markDead();
    MessageOut<EchoMessage> echoMessage = new MessageOut<EchoMessage>(MessagingService.Verb.ECHO, EchoMessage.instance, EchoMessage.serializer);
    logger.trace("Sending a EchoMessage to {}", addr);
    IAsyncCallback echoHandler = new IAsyncCallback() {

        public boolean isLatencyForSnitch() {
            return false;
        }

        public void response(MessageIn msg) {
            realMarkAlive(addr, localState);
        }
    };
    MessagingService.instance().sendRR(echoMessage, addr, echoHandler);
}
Also used : MessageIn(org.apache.cassandra.net.MessageIn) MessageOut(org.apache.cassandra.net.MessageOut) IAsyncCallback(org.apache.cassandra.net.IAsyncCallback)

Aggregations

IAsyncCallback (org.apache.cassandra.net.IAsyncCallback)2 MessageIn (org.apache.cassandra.net.MessageIn)2 MessageOut (org.apache.cassandra.net.MessageOut)2 Collection (java.util.Collection)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Mutation (org.apache.cassandra.db.Mutation)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1