Examples of EncodingMetadata


Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

    final String k2 = MemcachedDriverTest.keyPrefix + "_key_famous";
    final List<String> keys = new ArrayList<String> ();
    keys.add (k1);
    keys.add (k2);
    final IOperationCompletionHandler<Map<String, KeyValueMessage>> handler = new TestLoggingHandler<Map<String, KeyValueMessage>> ("getBulk");
    final IResult<Map<String, KeyValueMessage>> r1 = this.wrapper.invokeGetBulkOperation (MemcachedDriverTest.keyPrefix, keys, new EncodingMetadata ("text/plain", "identity"), handler);
    try {
      KeyValueMessage mssg = r1.getResult ().get (k1);
      Assert.assertEquals ("fantastic", this.encoder.decode (mssg.getData (), new EncodingMetadata ("text/plain", "identity")));
      mssg = r1.getResult ().get (k2);
      Assert.assertEquals ("famous", this.encoder.decode (mssg.getData (), new EncodingMetadata ("text/plain", "identity")));
    } catch (final InterruptedException e) {
      this.exceptions.traceIgnoredException (e);
      Assert.fail ();
    } catch (final ExecutionException e) {
      this.exceptions.traceIgnoredException (e);
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

      throws IOException,
        ClassNotFoundException,
        EncodingException
  {
    final String k1 = MemcachedDriverTest.keyPrefix + "_key_fabulous";
    final byte[] b1 = this.encoder.encode ("it is ", new EncodingMetadata ("text/plain", "identity")).data;
    final KeyValueMessage mssg1 = new KeyValueMessage (k1, b1, "identity", "text/plain");
    final IOperationCompletionHandler<Boolean> handler = new TestLoggingHandler<Boolean> ("prepend");
    final IResult<Boolean> r1 = this.wrapper.invokePrependOperation (MemcachedDriverTest.keyPrefix, mssg1, handler);
    try {
      Assert.assertTrue (r1.getResult ());
    } catch (final InterruptedException e) {
      this.exceptions.traceIgnoredException (e);
      Assert.fail ();
    } catch (final ExecutionException e) {
      this.exceptions.traceIgnoredException (e);
      Assert.fail ();
    }
    final IOperationCompletionHandler<KeyValueMessage> handler1 = new TestLoggingHandler<KeyValueMessage> ("Get after prepend");
    final IResult<KeyValueMessage> r2 = this.wrapper.invokeGetOperation (MemcachedDriverTest.keyPrefix, k1, new EncodingMetadata ("text/plain", "identity"), handler1);
    try {
      final KeyValueMessage mssg = r2.getResult ();
      Assert.assertEquals ("it is fantabulous and miraculous", this.encoder.decode (mssg.getData (), new EncodingMetadata ("text/plain", "identity")));
    } catch (final InterruptedException e) {
      this.exceptions.traceIgnoredException (e);
      Assert.fail ();
    } catch (final ExecutionException e) {
      this.exceptions.traceIgnoredException (e);
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

      throws IOException,
        ClassNotFoundException,
        EncodingException
  {
    final String k1 = MemcachedDriverTest.keyPrefix + "_key_fabulous";
    final byte[] b1 = this.encoder.encode ("fantabulous", new EncodingMetadata ("text/plain", "identity")).data;
    final KeyValueMessage mssg1 = new KeyValueMessage (k1, b1, "identity", "text/plain");
    final IOperationCompletionHandler<Boolean> handler = new TestLoggingHandler<Boolean> ("replace");
    final IResult<Boolean> r1 = this.wrapper.invokeReplaceOperation (MemcachedDriverTest.keyPrefix, mssg1, 30, handler);
    try {
      Assert.assertTrue (r1.getResult ());
    } catch (final InterruptedException e) {
      this.exceptions.traceIgnoredException (e);
      Assert.fail ();
    } catch (final ExecutionException e) {
      this.exceptions.traceIgnoredException (e);
      Assert.fail ();
    }
    final IOperationCompletionHandler<KeyValueMessage> handler1 = new TestLoggingHandler<KeyValueMessage> ("Get after replace");
    final IResult<KeyValueMessage> r2 = this.wrapper.invokeGetOperation (MemcachedDriverTest.keyPrefix, k1, new EncodingMetadata ("text/plain", "identity"), handler1);
    try {
      final KeyValueMessage mssg = r2.getResult ();
      Assert.assertEquals ("fantabulous", this.encoder.decode (mssg.getData (), new EncodingMetadata ("text/plain", "identity")));
    } catch (final InterruptedException e) {
      this.exceptions.traceIgnoredException (e);
      Assert.fail ();
    } catch (final ExecutionException e) {
      this.exceptions.traceIgnoredException (e);
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

  public void testSet ()
      throws IOException,
        EncodingException
  {
    final String k1 = MemcachedDriverTest.keyPrefix + "_key_fantastic";
    final byte[] bytes1 = this.encoder.encode ("fantastic", new EncodingMetadata ("text/plain", "identity")).data;
    KeyValueMessage mssg = new KeyValueMessage (k1, bytes1, "identity", "text/plain");
    final IOperationCompletionHandler<Boolean> handler1 = new TestLoggingHandler<Boolean> ("set 1");
    final IResult<Boolean> r1 = this.wrapper.invokeSetOperation (MemcachedDriverTest.keyPrefix, mssg, 30, handler1);
    Assert.assertNotNull (r1);
    final String k2 = MemcachedDriverTest.keyPrefix + "_key_famous";
    final byte[] bytes2 = this.encoder.encode ("famous", new EncodingMetadata ("text/plain", "identity")).data;
    mssg = new KeyValueMessage (k2, bytes2, "identity", "text/plain");
    final IOperationCompletionHandler<Boolean> handler2 = new TestLoggingHandler<Boolean> ("set 2");
    final IResult<Boolean> r2 = this.wrapper.invokeSetOperation (MemcachedDriverTest.keyPrefix, mssg, 30, handler2);
    Assert.assertNotNull (r2);
    try {
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

        final Object outcome;
        if (outcomeClass == Map.class) {
          final Map<String, TValue> values = new HashMap<String, TValue> ();
          for (final KVEntry entry : resultEntries) {
            final Envelope envelope = entry.getEnvelope ();
            final EncodingMetadata encodingMetadata = new EncodingMetadata (envelope.getContentType (), envelope.getContentEncoding ());
            final TValue value;
            final byte[] rawValue = resultEntries.get (0).getValue ().toByteArray ();
            if ((rawValue != null) && (rawValue.length > 0)) {
              try {
                value = this.encoder.decode (rawValue, encodingMetadata);
              } catch (final EncodingException exception) {
                this.exceptions.traceDeferredException (exception, "decoding the value for record failed; deferring!");
                this.pendingRequests.fail (token.getMessageId (), exception);
                break;
              }
            } else {
              value = null;
            }
            values.put (entry.getKey (), value);
          }
          outcome = values;
        } else if (outcomeClass == Object.class) {
          final TValue value;
          if (!resultEntries.isEmpty ()) {
            final byte[] rawValue = resultEntries.get (0).getValue ().toByteArray ();
            if ((rawValue != null) && (rawValue.length > 0)) {
              final Envelope envelope = resultEntries.get (0).getEnvelope ();
              final EncodingMetadata encodingMetadata = new EncodingMetadata (envelope.getContentType (), envelope.getContentEncoding ());
              try {
                value = this.encoder.decode (rawValue, encodingMetadata);
              } catch (final EncodingException exception) {
                this.exceptions.traceDeferredException (exception, "decoding the value for record failed; deferring!");
                this.pendingRequests.fail (token.getMessageId (), exception);
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("getting the record with key `%s` (and `%d` other keys) (with request token `%s`)...", keys.get (0), Integer.valueOf (keys.size () - 1), token.getMessageId ());
    final GetRequest.Builder requestBuilder = GetRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.addAllKey (keys);
    final EncodingMetadata encodingMetadata = this.encoder.getExpectedEncodingMetadata ();
    requestBuilder.setEnvelope (this.buildEnvelope (encodingMetadata));
    final Message message = new Message (KeyValueMessage.GET_REQUEST, requestBuilder.build ());
    return (this.sendRequest (message, token, outcomeClass));
  }
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

   
    @Override
    public void handleDelivery (final AmqpInboundMessage message)
    {
      String recvMessage;
      final EncodingMetadata encoding = new EncodingMetadata (message.getContentType (), message.getContentEncoding ());
      try {
        recvMessage = AmqpDriverTest.this.encoder.decode (message.getData (), encoding);
        Assert.assertTrue ("Received message: " + recvMessage, AmqpDriverTest.this.sentMessage.equals (recvMessage));
      } catch (final EncodingException e) {
        Assert.fail ("Delivery exception " + e.getMessage ());
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

        final KeyValuePayloads.GetRequest getRequest = (GetRequest) message.payload;
        if (getRequest.getKeyCount () > 1) {
          token = getRequest.getToken ();
          MemcachedStub.logger.trace (mssgPrefix + "GET_BULK " + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
          callback = new DriverOperationFinishedHandler (token, session, MemcachedDriver.class, MemcachedResponseTransmitter.class);
          final EncodingMetadata expectedEncoding = new EncodingMetadata (getRequest.getEnvelope ().getContentType (), getRequest.getEnvelope ().getContentEncoding ());
          final IResult<Map<String, eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage>> resultGet = driver.invokeGetBulkOperation (token.getClientId (), getRequest.getKeyList (), expectedEncoding, callback);
          callback.setDetails (KeyValueOperations.GET_BULK, resultGet);
          handle = true;
        }
      }
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

      public Map<String, KeyValueMessage> call ()
          throws ExecutionException,
            InterruptedException
      {
        final String[] keys = (String[]) parameters[0];
        final EncodingMetadata expectedEncoding = (EncodingMetadata) parameters[1];
        final Future<Map<String, Object>> opResult = MemcachedOperationFactory.this.mcClient.asyncGetBulk (keys);
        final Map<String, KeyValueMessage> result = new HashMap<String, KeyValueMessage> ();
        KeyValueMessage kvMessage = null;
        for (final Map.Entry<String, Object> entry : opResult.get ().entrySet ()) {
          kvMessage = null;
          kvMessage = new KeyValueMessage (entry.getKey (), (byte[]) entry.getValue (), expectedEncoding.getContentEncoding (), expectedEncoding.getContentType ());
          result.put (entry.getKey (), kvMessage);
        }
        return result;
      }
    });
View Full Code Here

Examples of eu.mosaic_cloud.platform.core.utils.EncodingMetadata

      public KeyValueMessage call ()
          throws ExecutionException,
            InterruptedException
      {
        final String key = (String) parameters[0];
        final EncodingMetadata expectedEncoding = (EncodingMetadata) parameters[1];
        final Future<Object> opResult = MemcachedOperationFactory.this.mcClient.asyncGet (key);
        final byte[] data = (byte[]) opResult.get ();
        KeyValueMessage kvMessage = null;
        kvMessage = new KeyValueMessage (key, data, expectedEncoding.getContentEncoding (), expectedEncoding.getContentType ());
        return kvMessage;
      }
    });
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.