//###
//# #%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 java.util.Collection;
import java.util.Iterator;
import specs.eu.data_structures.InterfaceRequirementNode;
import specs.eu.data_structures.InterfaceWeightedEdge;
import specs.eu.parser.RequirementAlreadyPresentException;
import specs.eu.parser.XMLTreeInstantiator;
import edu.uci.ics.jung.graph.Tree;
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.platform.core.utils.SerializedDataEncoder;
import eu.mosaic_cloud.tools.callbacks.core.CallbackCompletion;
public class PushQPT
{
public static final class AmqpPublisherCallback
extends DefaultAmqpPublisherConnectorCallback<PushQPTContext, QPT, Void>
{
@Override
public CallbackCompletion<Void> destroySucceeded (final PushQPTContext context, final CallbackArguments arguments)
{
this.logger.info ("PushQPT [Publisher] destroyed successfully.");
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> initializeSucceeded (final PushQPTContext context, final CallbackArguments arguments)
{
this.logger.info ("PushQPT [Publisher] initialized successfully.");
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> publishSucceeded (final PushQPTContext context, final GenericCallbackCompletionArguments<Void> arguments)
{
//context.cloudlet.destroy ();
this.logger.info ("PushQPT [Push] successfully.");
return ICallback.SUCCESS;
}
}
public static final class LifeCycleHandler
extends DefaultCloudletCallback<PushQPTContext>
{
@Override
public CallbackCompletion<Void> destroy (final PushQPTContext context, final CloudletCallbackArguments<PushQPTContext> arguments)
{
this.logger.info ("PushQPT is being destroyed...");
return CallbackCompletion.createAndChained (context.publisher.destroy());
}
@Override
public CallbackCompletion<Void> destroySucceeded (final PushQPTContext context, final CloudletCallbackCompletionArguments<PushQPTContext> arguments)
{
this.logger.info ("PushQPT was destroyed successfully.");
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> initialize (final PushQPTContext context, final CloudletCallbackArguments<PushQPTContext> arguments)
{
this.logger.info ("PushQPT initializing...");
context.cloudlet = arguments.getCloudlet ();
final IConfiguration configuration = context.cloudlet.getConfiguration ();
final IConfiguration queueConfiguration2 = configuration.spliceConfiguration (ConfigurationIdentifier.resolveAbsolute ("queueqpt.publisher"));
context.publisher = context.cloudlet.getConnectorFactory (IAmqpQueuePublisherConnectorFactory.class).create (queueConfiguration2, QPT.class, JsonDataEncoder.create(QPT.class), new AmqpPublisherCallback (), context);
return CallbackCompletion.createAndChained (context.publisher.initialize ());
}
@Override
public CallbackCompletion<Void> initializeSucceeded (final PushQPTContext context, final CloudletCallbackCompletionArguments<PushQPTContext> arguments)
{
this.logger.info ("PushQPT initialized successfully.");
context.qpt=new QPT();
context.qpt.setName("Giuseppe");
context.qpt.setSecLa("RAK");
context.qpt.setVal(10);
this.logger.info ("PushQPT Push");
context.publisher.publish(context.qpt, null);
return ICallback.SUCCESS;
}
}
public static final class PushQPTContext
{
ICloudletController<PushQPTContext> cloudlet;
IAmqpQueuePublisherConnector<QPT, Void> publisher;
QPT qpt;
}
}