Package net.tomp2p.message

Examples of net.tomp2p.message.DataMap


    private FutureResponse put(final PeerAddress remotePeer, final PutBuilder putBuilder, final Type type,
            final ChannelCreator channelCreator) {

        Utils.nullCheck(remotePeer);

        final DataMap dataMap;
        if (putBuilder.dataMap() != null) {
            dataMap = new DataMap(putBuilder.dataMap());
        } else {
            dataMap = new DataMap(putBuilder.locationKey(), putBuilder.domainKey(),
                    putBuilder.versionKey(), putBuilder.dataMapContent());
        }

        final Message message = createMessage(remotePeer, RPC.Commands.PUT.getNr(), type);
View Full Code Here


    public FutureResponse putMeta(final PeerAddress remotePeer, final PutBuilder putBuilder,
            final ChannelCreator channelCreator) {

        Utils.nullCheck(remotePeer);

        final DataMap dataMap;
        if (putBuilder.dataMap() != null) {
            dataMap = new DataMap(putBuilder.dataMap());
        } else {
            dataMap = new DataMap(putBuilder.locationKey(), putBuilder.domainKey(),
                    putBuilder.versionKey(), putBuilder.dataMapContent());
        }
       
        final Type type;
        if (putBuilder.changePublicKey()!=null) {
View Full Code Here

  public FutureResponse putConfirm(final PeerAddress remotePeer, final PutBuilder putBuilder,
      final ChannelCreator channelCreator) {

    Utils.nullCheck(remotePeer);

    final DataMap dataMap;
    if (putBuilder.dataMap() != null) {
      dataMap = new DataMap(putBuilder.dataMap());
    } else {
      dataMap = new DataMap(putBuilder.locationKey(), putBuilder.domainKey(),
          putBuilder.versionKey(), putBuilder.dataMapContent());
    }

    final Message message = createMessage(remotePeer, RPC.Commands.PUT_CONFIRM.getNr(), Type.REQUEST_1);
View Full Code Here

        if (addBuilder.isSign()) {
            message.publicKeyAndSign(addBuilder.keyPair());
        }

        message.setDataMap(new DataMap(addBuilder.locationKey(), addBuilder.domainKey(), addBuilder
                .versionKey(), dataMap));

        final FutureResponse futureResponse = new FutureResponse(message);
        final RequestHandler<FutureResponse> request = new RequestHandler<FutureResponse>(futureResponse,
                peerBean(), connectionBean(), addBuilder);
View Full Code Here

    }
   
    private void handlePutMeta(Message message, Message responseMessage, boolean isDomain) {
      LOG.debug("handlePutMeta {}", message);
      final PublicKey publicKey = message.publicKey(0);
        final DataMap toStore = message.dataMap(0);
        final Map<Number640, Byte> result;
        final int dataSize;
        if(isDomain) {
          dataSize = 1;
          result = new HashMap<Number640, Byte>(1);
          LOG.debug("received meta request to change domain");
          Number160 locationKey = message.key(0);
          Number160 domainKey = message.key(1);
          final Number640 key = new Number640(locationKey, domainKey, Number160.ZERO, Number160.ZERO);
          PublicKey publicKeyChange = message.publicKey(1);
          Enum<?> status = storageLayer.updateMeta(key.locationAndDomainKey(), publicKey, publicKeyChange);
          result.put(key, (byte) status.ordinal());
        } else {
          dataSize = toStore.size();
            result = new HashMap<Number640, Byte>(dataSize);
          LOG.debug("received meta request to change entry");
          for (Map.Entry<Number640, Data> entry : toStore.dataMap().entrySet()) {
            entry.getValue().meta();
            Enum<?> status = storageLayer.updateMeta(publicKey, entry.getKey(), entry.getValue());
            result.put(entry.getKey(), (byte) status.ordinal());
          }
        }
View Full Code Here

                    }
                    newDataMap.put(key, data);
                }
            }
            if (newDataMap.size() > 0) {
                return new DataMap(newDataMap);
            } else {
                throw new IllegalArgumentException("Need either dataMap, key, or keys!");
            }
        }
    }
View Full Code Here

                            LOG.error("checkDirect failed {}", future.failedReason());
                            return;
                        }

                        Message responseMessage = future.responseMessage();
                        DataMap dataMap = responseMessage.dataMap(0);

                        if (dataMap == null) {
                          LOG.error("nothing received, something is wrong");
                            futureSync.failed("nothing received, something is wrong");
                            return;
                        }

                        Map<Number640, Data> retVal = new HashMap<Number640, Data>();
                        boolean syncMessageRequired = false;
                        int dataCopy = 0;
                        int dataOrig = 0;
                        //int dataCopyCount = 0;
                        //int diffCount = 0;
                        //int dataNotCopied = 0;
                        for (Map.Entry<Number640, Data> entry : dataMap.dataMap().entrySet()) {
                         
                          Data data = entry.getValue();
                          if(data.length() == 0) {
                            if(data.isFlag1()) {
                              LOG.debug("no sync required");
                              syncMessageRequired = false;
                            } else if(data.isFlag2()) {
                              LOG.debug("copy required for key {}",entry.getKey());
                              syncMessageRequired = true;
                              Data data2 = peer.storageLayer().get(entry.getKey());
                              dataOrig += data2.length();
                              //copy
                                    retVal.put(entry.getKey(), data2);
                                    dataCopy += data2.length();
                                   
                            }
                          } else {
                            LOG.debug("sync required");
                            syncMessageRequired = true;
                            Data data2 = peer.storageLayer().get(entry.getKey());
                            dataOrig += data2.length();
                            final ByteBuf buffer = data.buffer();
                            Number160 versionKey = SyncUtils.decodeHeader(buffer);
                            Number160 hash = SyncUtils.decodeHeader(buffer);
            
                            List<Checksum> checksums = SyncUtils.decodeChecksums(buffer);
                            // TODO: don't copy data, toBytes does a copy!
                            List<Instruction> instructions = RSync.instructions(
                                         data2.toBytes(), checksums, blockSize);
                           
                            AlternativeCompositeByteBuf abuf = AlternativeCompositeByteBuf.compBuffer();
                           
                            dataCopy += SyncUtils.encodeInstructions(instructions, versionKey, hash, abuf);
                            DataBuffer dataBuffer = new DataBuffer(abuf);
                            //diff
                            Data data1 = new Data(dataBuffer).flag1();
                                retVal.put(entry.getKey(), data1);                       
                          }
                        }
                        final SyncStat syncStat = new SyncStat(peer.peerAddress().peerId(), other.peerId(), dataCopy, dataOrig);
                        if (syncMessageRequired) {
                          SyncBuilder.this.dataMap(new DataMap(retVal));
                          FutureResponse fr = peerSync.syncRPC().syncMessage(other,
                                    SyncBuilder.this, future2.channelCreator());
                            fr.addListener(new BaseFutureAdapter<FutureResponse>() {
                                @Override
                                public void operationComplete(FutureResponse future) throws Exception {
View Full Code Here

    private Message handlePut(final Message message, final Message responseMessage,
            final boolean putIfAbsent, final boolean protectDomain) throws IOException {
      LOG.debug("handlePut {}", message);
        final PublicKey publicKey = message.publicKey(0);
        final DataMap toStore = message.dataMap(0);
        final int dataSize = toStore.size();
        final Map<Number640, Byte> result = new HashMap<Number640, Byte>(dataSize);
        for (Map.Entry<Number640, Data> entry : toStore.dataMap().entrySet()) {
            Enum<?> putStatus = doPut(putIfAbsent, protectDomain, publicKey, entry.getKey(), entry.getValue());
            result.put(entry.getKey(), (byte) putStatus.ordinal());
            // check the responsibility of the newly added data, do something
            // (notify) if we are responsible
            if (!entry.getValue().hasPrepareFlag()) {
View Full Code Here

    }

  private void handlePutConfirm(final Message message, final Message responseMessage) throws IOException {
    LOG.debug("handlePutConfirm {}", message);
    final PublicKey publicKey = message.publicKey(0);
    final DataMap toStore = message.dataMap(0);
    final int dataSize = toStore.size();
    final Map<Number640, Byte> result = new HashMap<Number640, Byte>(dataSize);
    LOG.debug("Received put confirmation.");
    for (Map.Entry<Number640, Data> entry : toStore.dataMap().entrySet()) {
      Enum<?> status = storageLayer.putConfirm(publicKey, entry.getKey(), entry.getValue());
      result.put(entry.getKey(), (byte) status.ordinal());
     
      if ((status == PutStatus.OK || status == PutStatus.VERSION_FORK)
              && replicationListener != null) {
View Full Code Here

    private Message handleAdd(final Message message, final Message responseMessage,
            final boolean protectDomain) {
      LOG.debug("handleAdd {}", message);
        Utils.nullCheck(message.dataMap(0));
        final Map<Number640, Byte> result = new HashMap<Number640, Byte>();
        final DataMap dataMap = message.dataMap(0);
        final PublicKey publicKey = message.publicKey(0);
        final boolean list = isList(message);
        // here we set the map with the close peers. If we get data by a
        // sender and the sender is closer than us, we assume that the sender has
        // the data and we don't need to transfer data to the closest (sender)
        // peer.

        for (Map.Entry<Number640, Data> entry : dataMap.dataMap().entrySet()) {
            Enum<?> status = doAdd(protectDomain, entry, publicKey, list, storageLayer, peerBean().serverPeerAddress());
            result.put(entry.getKey(), (byte) status.ordinal());

            // check the responsibility of the newly added data, do something
            // (notify) if we are responsible
View Full Code Here

TOP

Related Classes of net.tomp2p.message.DataMap

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.