Java tutorial
/** * Copyright (C) 2011 Pedro Mauricio Costa <pm.costa [at] imperial [dot] ac [dot] uk> * * This file is part of Cloud2Bubble <http://www.cloud2bubble.com>. * * Cloud2Bubble is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Cloud2Bubble is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser Public License for more details. * * You should have received a copy of the GNU Lesser Public License * along with Cloud2Bubble. If not, see <http://www.gnu.org/licenses/>. */ package net.ponder2.managedobject; import net.ponder2.ManagedObject; import net.ponder2.apt.Ponder2op; import net.ponder2.exception.Ponder2ArgumentException; import net.ponder2.exception.Ponder2Exception; import net.ponder2.exception.Ponder2OperationException; import net.ponder2.managedobject.MessagingQueue.Consumer; import net.ponder2.objects.P2Object; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.cloud2bubble.entities.Environment; import com.cloud2bubble.services.FuzzyEngine; import com.cloud2bubble.util.C2BUtils; /** * Interface point between Ponder2 and the Reasoner engine. * * @author Pedro Mauricio Costa <pm.costa@imperial.ac.uk> * */ public class Reasoner implements ManagedObject, Consumer { private static final Log log = LogFactory.getLog(Reasoner.class); private FuzzyEngine fuzzyEngine; //private MessagingQueue mq; // @Deprecated // private Thread consumer = new Thread() { // public void run() { // Message msg; // // while (true) { // if ((mq == null) || ((msg = mq.receive()) == null)) { // try { // Thread.sleep(500); // } catch (InterruptedException e) { // log.error(e); // } // } else { // fuzzyEngine.evaluate(msg); // msg.sendReply(); // } // } // } // }; @Ponder2op("create") public Reasoner() { fuzzyEngine = FuzzyEngine.getInstance(); //consumer.start(); } // @Ponder2op("messaging:") // public void setMessagingQueue(P2Object mq) { // // this.mq = (MessagingQueue) ((P2ObjectAdaptor) mq).getObj(); // } @Ponder2op("qoe_event:") public void qoeEventEntrypoint(P2Object c2bEvent) { try { P2Object[] props = c2bEvent.asArray(); Bubble bubble = C2BUtils.getBubble(props[0].asString()); Double qoe = fuzzyEngine.evaluateQoe(C2BUtils.getCloudlet(props[1].asString()), bubble); C2BUtils.updateBubble(bubble.getId(), Environment.QOE.toString(), qoe.toString()); } catch (Ponder2ArgumentException e) { log.error(e); } catch (Ponder2OperationException e) { log.error(e); } catch (Ponder2Exception e) { log.error(e); } } }