Package eu.mosaic_cloud.portingtest

Source Code of eu.mosaic_cloud.portingtest.ConsumerQPTKVStringKV$LifeCycleHandler

//###
//# #%L
//# mosaic-java-sun-utilities
//# %%
//# Copyright (C) 2010 - 2012 Seconda Università di Napoli
//#Authors: Massimiliano Rak, Giuseppe Aversano
//# %%
//# Licensed under the Apache License, Version 2.0 (the "License");
//# you may not use this file except in compliance with the License.
//# You may obtain a copy of the License at
//#
//#      http://www.apache.org/licenses/LICENSE-2.0
//#
//# Unless required by applicable law or agreed to in writing, software
//# distributed under the License is distributed on an "AS IS" BASIS,
//# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//# See the License for the specific language governing permissions and
//# limitations under the License.
//# #L%
//###

package eu.mosaic_cloud.portingtest;

import eu.mosaic_cloud.cloudlets.connectors.kvstore.IKvStoreConnector;
import eu.mosaic_cloud.cloudlets.connectors.kvstore.IKvStoreConnectorFactory;
import eu.mosaic_cloud.cloudlets.connectors.kvstore.KvStoreCallbackCompletionArguments;
import eu.mosaic_cloud.cloudlets.connectors.queue.amqp.AmqpQueueConsumeCallbackArguments;
import eu.mosaic_cloud.cloudlets.connectors.queue.amqp.IAmqpQueueConsumerConnector;
import eu.mosaic_cloud.cloudlets.connectors.queue.amqp.IAmqpQueueConsumerConnectorFactory;
import eu.mosaic_cloud.cloudlets.connectors.queue.amqp.IAmqpQueuePublisherConnector;
import eu.mosaic_cloud.cloudlets.connectors.queue.amqp.IAmqpQueuePublisherConnectorFactory;
import eu.mosaic_cloud.cloudlets.core.CallbackArguments;
import eu.mosaic_cloud.cloudlets.core.CloudletCallbackArguments;
import eu.mosaic_cloud.cloudlets.core.CloudletCallbackCompletionArguments;
import eu.mosaic_cloud.cloudlets.core.GenericCallbackCompletionArguments;
import eu.mosaic_cloud.cloudlets.core.ICallback;
import eu.mosaic_cloud.cloudlets.core.ICloudletController;
import eu.mosaic_cloud.cloudlets.tools.DefaultAmqpPublisherConnectorCallback;
import eu.mosaic_cloud.cloudlets.tools.DefaultAmqpQueueConsumerConnectorCallback;
import eu.mosaic_cloud.cloudlets.tools.DefaultCloudletCallback;
import eu.mosaic_cloud.cloudlets.tools.DefaultKvStoreConnectorCallback;
import eu.mosaic_cloud.platform.core.configuration.ConfigurationIdentifier;
import eu.mosaic_cloud.platform.core.configuration.IConfiguration;
import eu.mosaic_cloud.platform.core.utils.JsonDataEncoder;
import eu.mosaic_cloud.platform.core.utils.NullDataEncoder;
import eu.mosaic_cloud.platform.core.utils.PlainTextDataEncoder;
import eu.mosaic_cloud.portingtest.ConsumerByteKV.ConsumerByteKVContext;
import eu.mosaic_cloud.portingtest.ConsumerByteKV.KeyValueCallback;
import eu.mosaic_cloud.tools.callbacks.core.CallbackCompletion;


public class ConsumerQPTKVStringKV
{
 
 
  public static final class AmqpConsumerCallback
  extends DefaultAmqpQueueConsumerConnectorCallback<ConsumerQPTKVStringKVContext, QPT, Void>
{
@Override
public CallbackCompletion<Void> consume (final ConsumerQPTKVStringKVContext context, final AmqpQueueConsumeCallbackArguments<QPT> arguments)
{
  final QPT val = arguments.getMessage ();
 
  this.logger.info ("\n\n ConsumerQPTKVStringKV received  message");
  this.logger.info ("\n\n ConsumerQPTKVStringKV SecLa:"+val.getSecLa());
  this.logger.info ("\n\n ConsumerQPTKVStringKV nome:"+val.getName());
  this.logger.info ("\n\n ConsumerQPTKVStringKV media:"+val.getVal());

  context.kvStore.set(context.keyQPT,val, null);
 
  context.consumer.acknowledge (arguments.getToken ());
 
 
  return ICallback.SUCCESS;
}

@Override
public CallbackCompletion<Void> destroySucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV Consumer  destroyed successfully.");
  return ICallback.SUCCESS;
}

@Override
public CallbackCompletion<Void> initializeSucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV Consumer  initialized successfully.");
  return ICallback.SUCCESS;
}

public CallbackCompletion<Void> acknowledgeSucceeded (final ConsumerQPTKVStringKVContext context, final GenericCallbackCompletionArguments<Void> arguments)
{
//  context.cloudlet.destroy ();
  return ICallback.SUCCESS;
}
}

 
  public static final class KeyValueCallback
  extends DefaultKvStoreConnectorCallback<ConsumerQPTKVStringKVContext, QPT, Void>
{
@Override
public CallbackCompletion<Void> destroySucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV KV_QPT destroyed successfully.");
  return ICallback.SUCCESS;
}

 

@Override
public CallbackCompletion<Void> initializeSucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV KV_QPT initialized successfully");
    return ICallback.SUCCESS;
}

public CallbackCompletion<Void> setSucceeded(final ConsumerQPTKVStringKVContext context, final KvStoreCallbackCompletionArguments<QPT,Void> arguments) {
  this.logger.info("\n\nSet nel KV_QPT Contenente i Risultati memorizzati Succeeded\n\n");
  String k=arguments.getKey();
  //this.logger.info("\n\nKEY:"+k);
  QPT value=(QPT)arguments.getValue();
  //this.logger.info("\n\nResult:"+value);
 
  context.kvStore.get(context.keyQPT,null);

 
 
  return ICallback.SUCCESS;
}

public CallbackCompletion<Void> deleteSucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV KV_QPT delete successfully.");
  return ICallback.SUCCESS;
}

public CallbackCompletion<Void> getSucceeded(final ConsumerQPTKVStringKVContext context,final KvStoreCallbackCompletionArguments<QPT,Void> arguments) {
 
  this.logger.info("\n\nGet nel KV_QPT Contenente i Risultati memorizzati Succeeded\n\n");
  String key =(String) arguments.getKey();
  QPT value=(QPT) arguments.getValue();
 
  this.logger.info("\n\nKEY:"+key);
  this.logger.info ("\n\n GET ConsumerQPTKV SecLa:"+value.getSecLa());
  this.logger.info ("\n\n GET ConsumerQPTKV nome:"+value.getName());
  this.logger.info ("\n\n GET ConsumerQPTKV media:"+value.getVal());
 
  context.kvStoreString.set(context.keyString,"HELLO", null);
   

return ICallback.SUCCESS;
}

public CallbackCompletion<Void> ungetSucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV KV_QPT ungetSucceeded.");
  return ICallback.SUCCESS;
}

}
 
 
 
 
  public static final class KeyValueCallbackString
  extends DefaultKvStoreConnectorCallback<ConsumerQPTKVStringKVContext, String, Void>
{
@Override
public CallbackCompletion<Void> destroySucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV KV_String destroyed successfully.");
  return ICallback.SUCCESS;
}

 

@Override
public CallbackCompletion<Void> initializeSucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV KV_String initialized successfully");
    return ICallback.SUCCESS;
}

public CallbackCompletion<Void> setSucceeded(final ConsumerQPTKVStringKVContext context, final KvStoreCallbackCompletionArguments<String,Void> arguments) {
  this.logger.info("\n\nSet nel KV_String Contenente i Risultati memorizzati Succeeded\n\n");
  String k=arguments.getKey();
  this.logger.info("\n\nKEY:"+k);
  String value=(String)arguments.getValue();
  this.logger.info("\n\nResult:"+value);
 
  context.kvStoreString.get(context.keyString,null);

 
 
  return ICallback.SUCCESS;
}

public CallbackCompletion<Void> deleteSucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV KV_String  delete successfully.");
  return ICallback.SUCCESS;
}

public CallbackCompletion<Void> getSucceeded(final ConsumerQPTKVStringKVContext context,final KvStoreCallbackCompletionArguments<String,Void> arguments) {
 
  this.logger.info("\n\nGet nel KV_String Contenente i Risultati memorizzati Succeeded\n\n");
  String key =(String) arguments.getKey();
  String value=(String) arguments.getValue();
 
  this.logger.info("\n\nKEY:"+key);
  this.logger.info("\n\nResult:"+value);

 

   

return ICallback.SUCCESS;
}

public CallbackCompletion<Void> ungetSucceeded (final ConsumerQPTKVStringKVContext context, final CallbackArguments arguments)
{
  this.logger.info ("ConsumerQPTKVStringKV KV_String ungetSucceeded.");
  return ICallback.SUCCESS;
}

}
 
 
 
 
  public static final class LifeCycleHandler
      extends DefaultCloudletCallback<ConsumerQPTKVStringKVContext>
  {
    @Override
    public CallbackCompletion<Void> destroy (final ConsumerQPTKVStringKVContext context, final CloudletCallbackArguments<ConsumerQPTKVStringKVContext> arguments)
    {
      this.logger.info ("ConsumerQPTKV is being destroyed...");
      return CallbackCompletion.createAndChained (context.consumer.destroy ());
    }
   
    @Override
    public CallbackCompletion<Void> destroySucceeded (final ConsumerQPTKVStringKVContext context, final CloudletCallbackCompletionArguments<ConsumerQPTKVStringKVContext> arguments)
    {
      this.logger.info ("ConsumerQPTKV was destroyed successfully.");
      return ICallback.SUCCESS;
    }

    @Override
    public CallbackCompletion<Void> initialize (final ConsumerQPTKVStringKVContext context, final CloudletCallbackArguments<ConsumerQPTKVStringKVContext> arguments)
    {
      this.logger.info ("ConsumerQPTKV initializing...");
      context.cloudlet = arguments.getCloudlet ();
      final IConfiguration configuration = context.cloudlet.getConfiguration ();
      final IConfiguration queueConfiguration = configuration.spliceConfiguration (ConfigurationIdentifier.resolveAbsolute ("queueqpt.consumer"));
      final IConfiguration kvConfiguration = configuration.spliceConfiguration (ConfigurationIdentifier.resolveAbsolute ("storeqpt"));
      final IConfiguration kvConfigurationString = configuration.spliceConfiguration (ConfigurationIdentifier.resolveAbsolute ("storestring"));
      context.consumer = context.cloudlet.getConnectorFactory (IAmqpQueueConsumerConnectorFactory.class).create (queueConfiguration, QPT.class, JsonDataEncoder.create(QPT.class), new AmqpConsumerCallback (), context);
      context.kvStore = context.cloudlet.getConnectorFactory (IKvStoreConnectorFactory.class).create (kvConfiguration, QPT.class, JsonDataEncoder.create(QPT.class), new KeyValueCallback (), context);
      context.kvStoreString = context.cloudlet.getConnectorFactory (IKvStoreConnectorFactory.class).create (kvConfigurationString, String.class, PlainTextDataEncoder.create(), new KeyValueCallbackString (), context);
     
      return CallbackCompletion.createAndChained (context.consumer.initialize (),context.kvStore.initialize(),context.kvStoreString.initialize());
    }
   
   
    @Override
    public CallbackCompletion<Void> initializeSucceeded (final ConsumerQPTKVStringKVContext context, final CloudletCallbackCompletionArguments<ConsumerQPTKVStringKVContext> arguments)
    {
      this.logger.info ("ConsumerQPTKV initialized successfully.");
 
     
      return ICallback.SUCCESS;
    }
  }
 
  public static final class ConsumerQPTKVStringKVContext
  {
    ICloudletController<ConsumerQPTKVStringKVContext> cloudlet;
    IAmqpQueueConsumerConnector<QPT, Void> consumer;
    IKvStoreConnector<QPT, Void> kvStore;
    IKvStoreConnector<String, Void> kvStoreString;
    String keyQPT="keyQPT";
    String keyString="keyString";


  }
}
TOP

Related Classes of eu.mosaic_cloud.portingtest.ConsumerQPTKVStringKV$LifeCycleHandler

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.