Example usage for org.apache.cassandra.net MessagingService instance

List of usage examples for org.apache.cassandra.net MessagingService instance

Introduction

In this page you can find the example usage for org.apache.cassandra.net MessagingService instance.

Prototype

public static MessagingService instance() 

Source Link

Usage

From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java

License:Apache License

private void reConnect(InetAddress endpoint, VersionedValue versionedValue) {
    if (!getDatacenter(endpoint).equals(getDatacenter(public_ip)))
        return; // do nothing return back...

    try {/* w w  w . j a  va 2s . c  om*/
        InetAddress remoteIP = InetAddress.getByName(versionedValue.value);
        MessagingService.instance().getConnectionPool(endpoint).reset(remoteIP);
        logger.debug(String.format("Intiated reconnect to an Internal IP %s for the %s", remoteIP, endpoint));
    } catch (UnknownHostException e) {
        logger.error("Error in getting the IP address resolved: ", e);
    }
}

From source file:com.csforge.sstable.StorageConnection.java

License:Apache License

public boolean connect() {
    long start = System.nanoTime();
    long timeout = TimeUnit.MILLISECONDS.toNanos(DatabaseDescriptor.getRpcTimeout());
    while (System.nanoTime() - start < timeout) {
        targetVersion = 10;//w ww . j a  v  a2  s.  c om
        try {
            SocketChannel channel = SocketChannel.open();
            if (!Config.getOutboundBindAny())
                channel.bind(new InetSocketAddress(FBUtilities.getLocalAddress(), 0));
            channel.connect(new InetSocketAddress(host, DatabaseDescriptor.getStoragePort()));
            socket = channel.socket();
            socket.setTcpNoDelay(true);
            if (DatabaseDescriptor.getInternodeSendBufferSize() != null) {
                try {
                    socket.setSendBufferSize(DatabaseDescriptor.getInternodeSendBufferSize());
                } catch (SocketException se) {
                    System.err.println("Failed to set send buffer size on internode socket." + se);
                }
            }

            // SocketChannel may be null when using SSL
            WritableByteChannel ch = socket.getChannel();
            out = new BufferedDataOutputStreamPlus(
                    ch != null ? ch : Channels.newChannel(socket.getOutputStream()), BUFFER_SIZE);

            out.writeInt(MessagingService.PROTOCOL_MAGIC);
            writeHeader(out, targetVersion, false);
            out.flush();

            DataInputStream in = new DataInputStream(socket.getInputStream());
            int maxTargetVersion = in.readInt();
            MessagingService.instance().setVersion(host, maxTargetVersion);

            out.writeInt(MessagingService.current_version);
            CompactEndpointSerializationHelper.serialize(FBUtilities.getBroadcastAddress(), out);
            out.flush();
            return true;
        } catch (IOException e) {
            socket = null;
            e.printStackTrace();
            System.err.println("unable to connect to " + host + e);
            Uninterruptibles.sleepUninterruptibly(OPEN_RETRY_DELAY, TimeUnit.MILLISECONDS);
        }
    }
    return false;
}

From source file:edu.dprg.morphous.MoveSSTableTest.java

License:Apache License

@Deprecated
@SuppressWarnings("rawtypes")
public static void doInsertOnTemporaryCFForRangesChoosingEndpointManually(String ksName, String originalCfName,
        String tempCfName, Collection<Range<Token>> ranges) {
    for (Range<Token> range : ranges) {
        ColumnFamilyStore originalCfs = Keyspace.open(ksName).getColumnFamilyStore(originalCfName);
        ColumnFamilyStore tempCfs = Keyspace.open(ksName).getColumnFamilyStore(originalCfName);
        ColumnFamilyStore.AbstractScanIterator iterator = edu.uiuc.dprg.morphous.Util
                .invokePrivateMethodWithReflection(originalCfs, "getSequentialIterator",
                        DataRange.forKeyRange(range), System.currentTimeMillis());

        while (iterator.hasNext()) {
            Row row = iterator.next();//  w w w . ja va 2s.  c  o  m
            ColumnFamily data = row.cf;
            ColumnFamily tempData = TreeMapBackedSortedColumns.factory.create(ksName, tempCfName);
            tempData.addAll(data, null);

            ByteBuffer newKey = tempData
                    .getColumn(tempData.metadata().partitionKeyColumns().get(0).name.asReadOnlyBuffer())
                    .value();
            InetAddress destinationNode = edu.uiuc.dprg.morphous.Util.getNthReplicaNodeForKey(ksName, newKey,
                    1);

            RowMutation rm = new RowMutation(newKey, tempData);
            MessageOut<RowMutation> message = rm.createMessage();
            MessagingService.instance().sendRR(message, destinationNode); //TODO Maybe use more robust way to send message
        }
    }
}