Package eu.mosaic_cloud.portingtest

Source Code of eu.mosaic_cloud.portingtest.ConsumerQPT$ConsumerQPTContext

//###
//# #%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.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.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.tools.callbacks.core.CallbackCompletion;


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

 
 
  context.consumer.acknowledge (arguments.getToken ());
 
 
  return ICallback.SUCCESS;
}

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

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

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

    @Override
    public CallbackCompletion<Void> initialize (final ConsumerQPTContext context, final CloudletCallbackArguments<ConsumerQPTContext> arguments)
    {
      this.logger.info ("ConsumerQPT initializing...");
      context.cloudlet = arguments.getCloudlet ();
      final IConfiguration configuration = context.cloudlet.getConfiguration ();
      final IConfiguration queueConfiguration = configuration.spliceConfiguration (ConfigurationIdentifier.resolveAbsolute ("queueqpt.consumer"));
      context.consumer = context.cloudlet.getConnectorFactory (IAmqpQueueConsumerConnectorFactory.class).create (queueConfiguration, QPT.class, JsonDataEncoder.create(QPT.class), new AmqpConsumerCallback (), context);
      return CallbackCompletion.createAndChained (context.consumer.initialize ());
    }
   
   
    @Override
    public CallbackCompletion<Void> initializeSucceeded (final ConsumerQPTContext context, final CloudletCallbackCompletionArguments<ConsumerQPTContext> arguments)
    {
      this.logger.info ("ConsumerQPT initialized successfully.");
 
     
      return ICallback.SUCCESS;
    }
  }
 
  public static final class ConsumerQPTContext
  {
    ICloudletController<ConsumerQPTContext> cloudlet;
    IAmqpQueueConsumerConnector<QPT, Void> consumer;

  }
}
TOP

Related Classes of eu.mosaic_cloud.portingtest.ConsumerQPT$ConsumerQPTContext

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.