Package eu.mosaic_cloud.sla

Source Code of eu.mosaic_cloud.sla.PublisherSLA$PublisherSLAContext

//###
//# #%L
//# mosaic-java-benchmarks
//# %%
//# Copyright (C) 2010 - 2012 Seconda Università di Napoli
//#Authors: Massimiliano Rak, Giuseppe Aversano, Loredana Liccardo
//# %%
//# 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.sla;


import java.util.UUID;

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.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.PlainTextDataEncoder;
import eu.mosaic_cloud.platform.core.utils.SerializedDataEncoder;
import eu.mosaic_cloud.tools.callbacks.core.CallbackCompletion;


public class PublisherSLA
{
  public static final class AmqpPublisherCallback
      extends DefaultAmqpPublisherConnectorCallback<PublisherSLAContext, String, Void>
  {
    @Override
    public CallbackCompletion<Void> destroySucceeded (final PublisherSLAContext context, final CallbackArguments arguments)
    {
      this.logger.info ("PublisherSLA publisher destroyed successfully.");
      return ICallback.SUCCESS;
    }
   
    @Override
    public CallbackCompletion<Void> initializeSucceeded (final PublisherSLAContext context, final CallbackArguments arguments)
    {
      this.logger.info ("PublisherSLA publisher initialized successfully.");
      return ICallback.SUCCESS;
    }
   
    @Override
    public CallbackCompletion<Void> publishSucceeded (final PublisherSLAContext context, final GenericCallbackCompletionArguments<Void> arguments)
    {
      //****context.cloudlet.destroy ();
      return ICallback.SUCCESS;
    }
  }
 
  public static final class LifeCycleHandler
      extends DefaultCloudletCallback<PublisherSLAContext>
  {
    @Override
    public CallbackCompletion<Void> destroy (final PublisherSLAContext context, final CloudletCallbackArguments<PublisherSLAContext> arguments)
    {
      this.logger.info ("PublisherSLA destroying...");
      return context.publisher.destroy ();
    }
   
    @Override
    public CallbackCompletion<Void> destroySucceeded (final PublisherSLAContext context, final CloudletCallbackCompletionArguments<PublisherSLAContext> arguments)
    {
      this.logger.info ("PublisherSLA destroyed successfully.");
      return ICallback.SUCCESS;
    }
   
    @Override
    public CallbackCompletion<Void> initialize (final PublisherSLAContext context, final CloudletCallbackArguments<PublisherSLAContext> arguments)
    {
      this.logger.info ("PublisherSLA initializing...");
     
      context.cloudlet = arguments.getCloudlet ();
     
      final IConfiguration configuration = context.cloudlet.getConfiguration ();
     
      final IConfiguration queueConfiguration = configuration.spliceConfiguration
          (ConfigurationIdentifier.resolveAbsolute ("queueupdate"));
     
      //context.publisher = context.cloudlet.getConnectorFactory (IAmqpQueuePublisherConnectorFactory.class).create (queueConfiguration, String.class, SerializedDataEncoder.create (String.class), new AmqpPublisherCallback (), context);
     
      context.publisher = context.cloudlet.getConnectorFactory
          (IAmqpQueuePublisherConnectorFactory.class).create
          (queueConfiguration, String.class, JsonDataEncoder.create (String.class),
              new AmqpPublisherCallback (), context);
     
      return context.publisher.initialize ();
    }
   
    @Override
    public CallbackCompletion<Void> initializeSucceeded (final PublisherSLAContext context, final CloudletCallbackCompletionArguments<PublisherSLAContext> arguments)
    {
      this.logger.info ("PublisherSLA initialized successfully.");
      //context.publisher.publish (String.format ("Test message! (%s)", UUID.randomUUID ().toString ()), null);
      //String data="CIAO";
      //this.logger.info("Publish "+data);
      //context.publisher.publish(data, null);
     
     
      //System.out.println("\n\n Invio dei messaggi\n\n");
      //context.publisher.publish("FUNZIONA", null);
      //String data="CIAO";
      //context.publisher.publish(data, null);
     
           
      context.publisher.publish("{'type':'New','id':'1','rules':['state','request','(state==null && request==\"submitCFP\")','NewCFP','CAcfps']}", null);
      context.publisher.publish("{'type':'New','id':'2','rules':['state','request','(state==\"NewCFP\" && request==\"CAcfpSent\")','Evaluating','wait']}", null);
      context.publisher.publish("{'type':'New','id':'3','rules':['state','request','(state==\"NewCFP\" && request==\"submitCFP\")','NewCFP','discard']}", null);
      context.publisher.publish("{'type':'New','id':'4','rules':['state','request','(state==\"Evaluating\" && request==\"CAresponse\")','OptionsAvailable','wait']}", null);
    context.publisher.publish("{'type':'New','id':'5','rules':['state','request','(state==\"Evaluating\" && request==\"CAtimeout\")','Rejected','end']}", null);
    context.publisher.publish("{'type':'New','id':'6','rules':['state','request','(state==\"OptionsAvailable\" && request==\"CAresponse\")','OptionsAvailable','wait']}", null);
      context.publisher.publish("{'type':'New','id':'7','rules':['state','request','(state==\"OptionsAvailable\" && request==\"submitCFP\")','NewCFP','CAcfps']}", null);
      context.publisher.publish("{'type':'New','id':'8','rules':['state','request','(state==\"OptionsAvailable\" && request==\"submitProposal\")','ReserveRequest','CAreserve']}", null);
      context.publisher.publish("{'type':'New','id':'9','rules':['state','request','(state==\"ReserveRequest\" && request==\"CAreserveSent\")','Reserving','wait']}", null);
      context.publisher.publish("{'type':'New','id':'10','rules':['state','request','(state==\"Reserving\" && request==\"submitCFP\")','Reserving','discard']}", null);
      context.publisher.publish("{'type':'New','id':'11','rules':['state','request','(state==\"Reserving\" && request==\"submitProposal\")','Reserving','discard']}", null);
    context.publisher.publish("{'type':'New','id':'12','rules':['state','request','(state==\"Reserving\" && request==\"CAreserve\")','Reserved','wait']}", null);
      context.publisher.publish("{'type':'New','id':'13','rules':['state','request','(state==\"Reserved\" && request==\"sign\")','SignRequest','CAsign']}", null);
      context.publisher.publish("{'type':'New','id':'14','rules':['state','request','(state==\"SignRequest\" && request==\"submitCFP\")','SignRequest','discard']}", null);
      context.publisher.publish("{'type':'New','id':'15','rules':['state','request','(state==\"SignRequest\" && request==\"submitProposal\")','SignRequest','discard']}", null);
      context.publisher.publish("{'type':'New','id':'16','rules':['state','request','(state==\"SignRequest\" && request==\"CAsignSent\")','Signing','wait']}", null);
      context.publisher.publish("{'type':'New','id':'17','rules':['state','request','(state==\"Signing\" && request==\"submitCFP\")','Signing','discard']}", null);
      context.publisher.publish("{'type':'New','id':'18','rules':['state','request','(state==\"Signing\" && request==\"submitProposal\")','Signing','discard']}", null);
      context.publisher.publish("{'type':'New','id':'19','rules':['state','request','(state==\"Signing\" && request==\"CAsigned\")','Signed','wait']}", null);
      context.publisher.publish("{'type':'New','id':'20','rules':['state','request','(state==\"Signing\" && request==\"CArefused\")','Rejected','end']}", null);
    context.publisher.publish("{'type':'New','id':'21','rules':['state','request','(state==\"Signed\" && request==\"Terminate\")','TerminateRequest','CAterminate']}", null);
      context.publisher.publish("{'type':'New','id':'22','rules':['state','request','(state==\"TerminateRequest\" && request==\"CAterminateSent\")','Terminating','wait']}", null);
      context.publisher.publish("{'type':'New','id':'23','rules':['state','request','(state==\"Terminating\" && request==\"CAterminated\")','Terminated','end']}", null);
      context.publisher.publish("{'type':'New','id':'24','rules':['state','request','(state==\"Terminating\" && request==\"CArefused\")','Rejected','end']}", null);
      context.publisher.publish("{'type':'New','id':'25','rules':['state','request','(state==\"Reserving\" && request==\"CArefused\")','Rejected','end']}", null);
//    try {
//        Thread.sleep(30000);
//      } catch (InterruptedException e) {
//        // TODO Auto-generated catch block
//        e.printStackTrace();
//      }     

   
    context.publisher.publish("{'type':'Complete','number':'25','id':'26','rules':['parameter','expression','action']}", null);
     //System.out.println("\n\n {'type':'Complete','number':'25','id':'26','rules':['parameter','expression','action']}\n\n");
     
     
      return ICallback.SUCCESS;
    }
  }
 
  public static final class PublisherSLAContext
  {
    ICloudletController<PublisherSLAContext> cloudlet;
    IAmqpQueuePublisherConnector<String, Void> publisher;
  }
}
TOP

Related Classes of eu.mosaic_cloud.sla.PublisherSLA$PublisherSLAContext

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.