Package org.xtreemfs.foundation.buffer

Examples of org.xtreemfs.foundation.buffer.ReusableBuffer


       
        byte[] key = "testKey".getBytes();
        byte[] value = "testValue".getBytes();
       
        // store data to the buffer
        ReusableBuffer testBuffer = BufferPool.allocate(key.length + value.length);
               
        testBuffer.put(key);
        testBuffer.put(value);
        testBuffer.flip();
       
        // retrieve data from the buffer
        byte[] rKey = new byte[key.length];
        byte[] rValue = new byte[value.length];
       
        testBuffer.get(rKey, 0, key.length);
        assertEquals(new String(key), new String(rKey));
       
        testBuffer.get(rValue, 0, value.length);
        assertEquals(new String(value), new String (rValue));
    }
View Full Code Here


        // setup the client
        ReplicationClientAdapter testClient = new ReplicationClientAdapter(client,
                config.getInetSocketAddress());
       
        // run some test operations
        ReusableBuffer result = testClient.chunk(fileName, offsetStart, offsetEnd).get();
        assertEquals(chunkResult, new String(result.array()));
       
        testClient.heartbeat(lsn, port).get();
    }
View Full Code Here

     */
    @Override
    public void processRequest(final Request rq) {
       
        Lookup req = (Lookup) rq.getRequestMessage();
        ReusableBuffer data = rq.getData();
        byte[] key = (data != null) ? data.array() : null;
       
        Logging.logMessage(Logging.LEVEL_DEBUG, this, "PrefixLookupReverseOperation:" +
                "db %s, index %d, key %s.", req.getDatabaseName(), req.getIndexId(),
                (key == null) ? "null" : new String(key));
       
        try {         
            dbs.getDatabase(req.getDatabaseName()).reversePrefixLookup(req.getIndexId(), key,
                    null).registerListener(
                                new DatabaseRequestListener<ResultSet<byte[], byte[]>>() {
               
                @Override
                public void finished(ResultSet<byte[], byte[]> result, Object context) {
                    EntryMap.Builder r = EntryMap.newBuilder();
                   
                    // estimate the result size
                    int size = 0;
                    List<Entry<byte[], byte[]>> tmp = new ArrayList<Entry<byte[], byte[]>>();
                    while (result.hasNext()) {
                        Entry<byte[], byte[]> entry = result.next();
                        size += entry.getKey().length + entry.getValue().length;
                        tmp.add(entry);
                    }
                    result.free();
                   
                    // prepare the response
                    ReusableBuffer data = BufferPool.allocate(size);
                    for (Entry<byte[], byte[]> entry : tmp) {
                        r.addLength(entry.getKey().length);
                        r.addLength(entry.getValue().length);
                       
                        data.put(entry.getKey());
                        data.put(entry.getValue());
                    }
                    data.flip();
                   
                    rq.sendSuccess(r.build(), data);
                }
               
                @Override
View Full Code Here

                    "There are no slaves available anymore! " +
                    "BabuDB runs if it would be in non-replicated mode.");
        } else {
           
            // serialize the LogEntry
            ReusableBuffer payload = null;
            synchronized(checksum) {
                CRC32 csumAlgo = checksum.get();
                try {
                    payload = le.serialize(csumAlgo);
                } finally {
                    csumAlgo.reset();
                }
            }
           
            // send the LogEntry to the other servers
            for (final SlaveClient slave : slaves) {
                slave.replicate(le.getLSN(), payload.createViewBuffer()).registerListener(
                        new ClientResponseAvailableListener<Object>() {
               
                    @Override
                    public void responseAvailable(Object r) {
                       
View Full Code Here

    @Override
    public void processRequest(final Request rq) {
        RangeLookup req = (RangeLookup) rq.getRequestMessage();
       
        int limit = req.getFromLength()
        ReusableBuffer data = rq.getData();
        byte[] from = null;
        byte[] to = null;
        ReusableBuffer f = null;
        ReusableBuffer t = null;
        if (data != null) {
            f = data.createViewBuffer();
            f.limit(limit);
            from = f.getData();
            t = data.createViewBuffer();
            t.position(limit);
            to = t.getData();
        }
       
        Logging.logMessage(Logging.LEVEL_DEBUG, this, "RangeLookupOperation:" +
                "db %s, index %d, from %s, to %s.", req.getDatabaseName(), req.getIndexId(),
                (from == null) ? "null" : new String(from), (to == null) ? "null" : new String(to));
      
        try {
            dbs.getDatabase(req.getDatabaseName()).rangeLookup(req.getIndexId(),
                            from, to, null).registerListener(
                                        new DatabaseRequestListener<ResultSet<byte[], byte[]>>() {
               
                @Override
                public void finished(ResultSet<byte[], byte[]> result, Object context) {
                    EntryMap.Builder r = EntryMap.newBuilder();
                   
                    // estimate the result size
                    int size = 0;
                    List<Entry<byte[], byte[]>> tmp = new ArrayList<Entry<byte[], byte[]>>();
                    while (result.hasNext()) {
                        Entry<byte[], byte[]> entry = result.next();
                        size += entry.getKey().length + entry.getValue().length;
                        tmp.add(entry);
                    }
                    result.free();
                   
                    // prepare the response
                    ReusableBuffer data = BufferPool.allocate(size);
                    for (Entry<byte[], byte[]> entry : tmp) {
                        r.addLength(entry.getKey().length);
                        r.addLength(entry.getValue().length);
                       
                        data.put(entry.getKey());
                        data.put(entry.getValue());
                    }
                    data.flip();
                   
                    rq.sendSuccess(r.build(), data);
                }
               
                @Override
View Full Code Here

     */
    @Override
    public void processRequest(final Request rq) {
       
        Lookup req = (Lookup) rq.getRequestMessage();
        ReusableBuffer data = rq.getData();
        byte[] key = (data != null) ? data.array() : null;
       
        Logging.logMessage(Logging.LEVEL_DEBUG, this, "PrefixLookupOperation:" +
                "db %s, index %d, key %s.", req.getDatabaseName(), req.getIndexId(),
                (key == null) ? "null" : new String(key));
       
        try {           
            dbs.getDatabase(req.getDatabaseName()).prefixLookup(req.getIndexId(), key,
                    null).registerListener(
                            new DatabaseRequestListener<ResultSet<byte[], byte[]>>() {
               
                @Override
                public void finished(ResultSet<byte[], byte[]> result, Object context) {
                    EntryMap.Builder r = EntryMap.newBuilder();
                       
                    // estimate the result size
                    int size = 0;
                    List<Entry<byte[], byte[]>> tmp = new ArrayList<Entry<byte[], byte[]>>();
                    while (result.hasNext()) {
                        Entry<byte[], byte[]> entry = result.next();
                        size += entry.getKey().length + entry.getValue().length;
                        tmp.add(entry);
                    }
                    result.free();
                   
                    // prepare the response
                    ReusableBuffer data = BufferPool.allocate(size);
                    for (Entry<byte[], byte[]> entry : tmp) {
                        r.addLength(entry.getKey().length);
                        r.addLength(entry.getValue().length);
                       
                        data.put(entry.getKey());
                        data.put(entry.getValue());
                    }
                    data.flip();
                   
                    rq.sendSuccess(r.build(), data);
                }
               
                @Override
View Full Code Here

    @Override
    public void processRequest(final Request rq) {
        RangeLookup req = (RangeLookup) rq.getRequestMessage();
       
        int limit = req.getFromLength();      
        ReusableBuffer data = rq.getData();
        byte[] from = null;
        byte[] to = null;
        ReusableBuffer f = null;
        ReusableBuffer t = null;
        if (data != null) {
            f = data.createViewBuffer();
            f.limit(limit);
            from = f.getData();
            t = data.createViewBuffer();
            t.position(limit);
            to = t.getData();
        }
      
        Logging.logMessage(Logging.LEVEL_DEBUG, this, "RangeLookupReverseOperation:" +
                "db %s, index %d, from %s, to %s.", req.getDatabaseName(), req.getIndexId(),
                (from == null) ? "null" : new String(from), (to == null) ? "null" : new String(to));
       
        try {
            dbs.getDatabase(req.getDatabaseName()).reverseRangeLookup(req.getIndexId(),
                            from, to, null).registerListener(
                                        new DatabaseRequestListener<ResultSet<byte[], byte[]>>() {
               
                @Override
                public void finished(ResultSet<byte[], byte[]> result, Object context) {
                    EntryMap.Builder r = EntryMap.newBuilder();
                   
                    // estimate the result size
                    int size = 0;
                    List<Entry<byte[], byte[]>> tmp = new ArrayList<Entry<byte[], byte[]>>();
                    while (result.hasNext()) {
                        Entry<byte[], byte[]> entry = result.next();
                        size += entry.getKey().length + entry.getValue().length;
                        tmp.add(entry);
                    }
                    result.free();
                   
                    // prepare the response
                    ReusableBuffer data = BufferPool.allocate(size);
                    for (Entry<byte[], byte[]> entry : tmp) {
                        r.addLength(entry.getKey().length);
                        r.addLength(entry.getValue().length);
                       
                        data.put(entry.getKey());
                        data.put(entry.getValue());
                    }
                    data.flip();
                   
                    rq.sendSuccess(r.build(), data);
                }
               
                @Override
View Full Code Here

            String dbName, int indexId, ReusableBuffer from, ReusableBuffer to,
            InetSocketAddress master) {
       
        assert (master != null);
       
        ReusableBuffer payload = BufferPool.allocate(from.remaining() + to.remaining());
        payload.put(from);
        payload.put(to);
       
        try {
            RPCResponse<EntryMap> result = rlookup(master, AUTHENTICATION, USER_CREDENTIALS, dbName,
                    indexId, from.remaining(), payload);
           
View Full Code Here

            String dbName, int indexId, ReusableBuffer from, ReusableBuffer to,
            InetSocketAddress master) {
       
        assert (master != null);
       
        ReusableBuffer payload = BufferPool.allocate(from.remaining() + to.remaining());
        payload.put(from);
        payload.put(to);
       
        try {
            RPCResponse<EntryMap> result = rlookupReverse(master, AUTHENTICATION, USER_CREDENTIALS,
                    dbName, indexId, from.remaining(), payload);
           
View Full Code Here

     * @see org.xtreemfs.babudb.replication.service.clients.ConditionClient#flease(
     *          org.xtreemfs.foundation.flease.comm.FleaseMessage)
     */
    @Override
    public ClientResponseFuture<Object, ErrorCodeResponse> flease(FleaseMessage message) {
        ReusableBuffer payload = BufferPool.allocate(message.getSize());
        InetSocketAddress sender = message.getSender();
        message.serialize(payload);
        payload.flip();
       
        try {
            RPCResponse<ErrorCodeResponse> result = flease(null, AUTHENTICATION,
                        USER_CREDENTIALS, new String(sender.getAddress().getAddress()),
                        sender.getPort(), payload);
View Full Code Here

TOP

Related Classes of org.xtreemfs.foundation.buffer.ReusableBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.