Package org.apache.airavata.xbaya.interpretor

Source Code of org.apache.airavata.xbaya.interpretor.StandaloneNotificationSender

/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you 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.
*
*/

package org.apache.airavata.xbaya.interpretor;

import java.net.URI;
import java.util.List;

import org.apache.airavata.common.utils.StringUtil;
import org.apache.airavata.xbaya.XBayaConstants;
import org.apache.airavata.xbaya.graph.system.InputNode;
import org.apache.airavata.xbaya.graph.system.OutputNode;
import org.apache.airavata.xbaya.graph.util.GraphUtil;
import org.apache.airavata.xbaya.jython.lib.ServiceNotifiable;
import org.apache.airavata.xbaya.jython.lib.StandaloneServiceNotificationSender;
import org.apache.airavata.xbaya.jython.lib.WorkflowNotifiable;
import org.apache.airavata.xbaya.monitor.gui.MonitorEventHandler.NodeState;
import org.apache.airavata.xbaya.wf.Workflow;
import org.apache.axis2.addressing.EndpointReference;
import org.python.core.PyObject;

public class StandaloneNotificationSender implements WorkflowNotifiable {

    private Workflow workflow;
    private URI workflowID;

    public StandaloneNotificationSender(String topic, Workflow workflow) {
        this.workflow = workflow;
        this.workflowID = URI.create(StringUtil.convertToJavaIdentifier(topic));
    }

    @Override
    public EndpointReference getEventSink() {
        return new EndpointReference(XBayaConstants.DEFAULT_BROKER_URL.toString());
    }

    @Override
    public void workflowStarted(PyObject[] args, String[] keywords) {
        List<InputNode> inputs = GraphUtil.getInputNodes(this.workflow.getGraph());
        for (InputNode inputNode : inputs) {
            inputNode.getGUI().setBodyColor(NodeState.FINISHED.color);
        }

    }

    @Override
    public void workflowStarted(Object[] args, String[] keywords) {
        List<InputNode> inputs = GraphUtil.getInputNodes(this.workflow.getGraph());
        for (InputNode inputNode : inputs) {
            inputNode.getGUI().setBodyColor(NodeState.FINISHED.color);
        }
    }

    @Override
    public void workflowFinished(Object[] args, String[] keywords) {
        List<OutputNode> outputs = GraphUtil.getOutputNodes(this.workflow.getGraph());
        for (OutputNode outputNode : outputs) {
            outputNode.getGUI().setBodyColor(NodeState.EXECUTING.color);
        }

    }

    @Override
    public void sendingPartialResults(Object[] args, String[] keywords) {
        // noop

    }

    @Override
    public void workflowFinished(PyObject[] args, String[] keywords) {
        List<OutputNode> outputs = GraphUtil.getOutputNodes(this.workflow.getGraph());
        for (OutputNode outputNode : outputs) {
            outputNode.getGUI().setBodyColor(NodeState.EXECUTING.color);
        }

    }

    @Override
    public void workflowTerminated() {
        // noop

    }

    @Override
    public void workflowFailed(String message) {
        // noop

    }

    @Override
    public void workflowFailed(Throwable e) {
        // noop

    }

    @Override
    public void workflowFailed(String message, Throwable e) {
        // noop

    }

    @Override
    public ServiceNotifiable createServiceNotificationSender(String nodeID) {
        return new StandaloneServiceNotificationSender(this.workflow, this.workflowID);
    }

    @Override
    public void cleanup(){

    }

    public String getTopic() {
        return this.workflowID.toASCIIString();
    }
}
TOP

Related Classes of org.apache.airavata.xbaya.interpretor.StandaloneNotificationSender

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.