Search in sources :

Example 1 with StoreId

use of org.neo4j.kernel.impl.nioneo.store.StoreId in project graphdb by neo4j-attic.

the class MasterUtil method packResponseWithoutTransactionStream.

public static <T> Response<T> packResponseWithoutTransactionStream(GraphDatabaseService graphDb, SlaveContext context, T response) {
    XaDataSource ds = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager().getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME);
    StoreId storeId = ((NeoStoreXaDataSource) ds).getStoreId();
    return new Response<T>(response, storeId, TransactionStream.EMPTY);
}
Also used : StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) NeoStoreXaDataSource(org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)

Example 2 with StoreId

use of org.neo4j.kernel.impl.nioneo.store.StoreId in project graphdb by neo4j-attic.

the class Client method sendRequest.

protected <R> Response<R> sendRequest(RequestType<M> type, SlaveContext context, Serializer serializer, Deserializer<R> deserializer) {
    Triplet<Channel, ChannelBuffer, ByteBuffer> channelContext = null;
    try {
        // Send 'em over the wire
        channelContext = getChannel();
        Channel channel = channelContext.first();
        channelContext.second().clear();
        ChunkingChannelBuffer chunkingBuffer = new ChunkingChannelBuffer(channelContext.second(), channel, Protocol.MAX_FRAME_LENGTH);
        chunkingBuffer.writeByte(type.id());
        writeContext(type, context, chunkingBuffer);
        serializer.write(chunkingBuffer, channelContext.third());
        chunkingBuffer.done();
        // Read the response
        @SuppressWarnings("unchecked") BlockingReadHandler<ChannelBuffer> reader = (BlockingReadHandler<ChannelBuffer>) channel.getPipeline().get("blockingHandler");
        final Triplet<Channel, ChannelBuffer, ByteBuffer> finalChannelContext = channelContext;
        DechunkingChannelBuffer dechunkingBuffer = new DechunkingChannelBuffer(reader, DEFAULT_READ_RESPONSE_TIMEOUT_SECONDS) {

            @Override
            protected ChannelBuffer readNext() {
                ChannelBuffer result = super.readNext();
                if (result == null) {
                    channelPool.dispose(finalChannelContext);
                    throw new ComException("Channel has been closed");
                }
                return result;
            }
        };
        R response = deserializer.read(dechunkingBuffer, channelContext.third());
        StoreId storeId = readStoreId(dechunkingBuffer, channelContext.third());
        if (shouldCheckStoreId(type)) {
            assertCorrectStoreId(storeId);
        }
        TransactionStream txStreams = readTransactionStreams(dechunkingBuffer);
        return new Response<R>(response, storeId, txStreams);
    } catch (ClosedChannelException e) {
        channelPool.dispose(channelContext);
        throw new ComException(e);
    } catch (IOException e) {
        throw new ComException(e);
    } catch (InterruptedException e) {
        throw new ComException(e);
    } catch (Exception e) {
        throw new ComException(e);
    } finally {
        releaseChannel();
    }
}
Also used : BlockingReadHandler(org.jboss.netty.handler.queue.BlockingReadHandler) ClosedChannelException(java.nio.channels.ClosedChannelException) Channel(org.jboss.netty.channel.Channel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId)

Example 3 with StoreId

use of org.neo4j.kernel.impl.nioneo.store.StoreId in project graphdb by neo4j-attic.

the class MadeUpServerProcess method startup.

@Override
protected void startup(Long[] creationTimeAndStoreId) throws Throwable {
    MadeUpCommunicationInterface implementation = new MadeUpImplementation(new StoreId(creationTimeAndStoreId[0], creationTimeAndStoreId[1]));
    server = new MadeUpServer(implementation, 8888);
}
Also used : StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId)

Example 4 with StoreId

use of org.neo4j.kernel.impl.nioneo.store.StoreId in project graphdb by neo4j-attic.

the class TestCommunication method makeSureServerStoreIdsMustMatch.

@Test
public void makeSureServerStoreIdsMustMatch() throws Exception {
    MadeUpImplementation serverImplementation = new MadeUpImplementation(new StoreId(10, 10));
    MadeUpServer server = new MadeUpServer(serverImplementation, PORT);
    MadeUpClient client = new MadeUpClient(PORT, storeIdToUse);
    try {
        client.multiply(1, 2);
        fail();
    } catch (ComException e) {
    // Good
    } finally {
        client.shutdown();
        server.shutdown();
    }
}
Also used : StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId) Test(org.junit.Test)

Example 5 with StoreId

use of org.neo4j.kernel.impl.nioneo.store.StoreId in project graphdb by neo4j-attic.

the class TestCommunication method makeSureClientStoreIdsMustMatch.

@Test
public void makeSureClientStoreIdsMustMatch() throws Exception {
    MadeUpImplementation serverImplementation = new MadeUpImplementation(storeIdToUse);
    MadeUpServer server = new MadeUpServer(serverImplementation, PORT);
    MadeUpClient client = new MadeUpClient(PORT, new StoreId(10, 10));
    try {
        client.multiply(1, 2);
        fail();
    } catch (ComException e) {
    // Good
    } finally {
        client.shutdown();
        server.shutdown();
    }
}
Also used : StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId) Test(org.junit.Test)

Aggregations

StoreId (org.neo4j.kernel.impl.nioneo.store.StoreId)8 IOException (java.io.IOException)3 File (java.io.File)2 Test (org.junit.Test)2 NeoStoreXaDataSource (org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource)2 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)2 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 Channel (org.jboss.netty.channel.Channel)1 BlockingReadHandler (org.jboss.netty.handler.queue.BlockingReadHandler)1 Before (org.junit.Before)1 ComException (org.neo4j.com.ComException)1 Triplet (org.neo4j.helpers.Triplet)1 AbstractGraphDatabase (org.neo4j.kernel.AbstractGraphDatabase)1 BranchedDataException (org.neo4j.kernel.ha.BranchedDataException)1 Master (org.neo4j.kernel.ha.Master)1