All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ode.jacob.JacobObject Maven / Gradle / Ivy

/*
 * 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.ode.jacob;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Set;

import org.apache.ode.jacob.vpu.JacobVPU;

/**
 * Base class for constructs which rely on a Java method body to represent some
 * aspect of the process.
 */
public abstract class JacobObject implements Serializable {
    public abstract Set getImplementedMethods();

    /**
     * Get the unadorned (no package) name of this class.
     */
    protected String getClassName() {
        return getClass().getSimpleName();
    }

    protected static Object getExtension(Class extensionClass) {
        return JacobVPU.activeJacobThread().getExtension(extensionClass);
    }

    @SuppressWarnings("unchecked")
    protected static  T importChannel(String channelId, Class channelClass) {
        return (T) JacobVPU.activeJacobThread().importChannel(channelId, channelClass);
    }

    /**
     * Instantiation; the Java code instance(new F(x,y,z)) is
     * equivalent to F(x,y,z) in the process calculus.
     *
     * @param concretion the concretion of a process template
     */
    protected static void instance(JacobRunnable concretion) {
        JacobVPU.activeJacobThread().instance(concretion);
    }

    protected  T newChannel(Class channelType)
            throws IllegalArgumentException
    {
        return newChannel(channelType, null);
    }

    /**
     * Channel creation; the Java code Channel x = newChannel(XChannel.class) ...
     * is equivalent to (new x) ...  in the process calculus.
     */
    @SuppressWarnings("unchecked")
    protected  T newChannel(Class channelType, String description)
        throws IllegalArgumentException
    {
        return (T) JacobVPU.activeJacobThread().newChannel(channelType, getClassName(), description);
    }

    /**
     * Object; the Java code "object(x, ChannelListener)" is equivalent to
     * x ? ChannelListener in the process algebra.
     *
     * @param methodList method list for the communication reduction
     * @see JacobThread#object
     */
    protected static  T object(ChannelListener methodList) {
        JacobVPU.activeJacobThread().object(false, methodList);
        return methodList.getChannel();
    }

    protected static void object(boolean replication, ChannelListener methodList) {
        JacobVPU.activeJacobThread().object(replication, methodList);
    }

    protected static void object(boolean replication, ChannelListener[] methodLists) {
        JacobVPU.activeJacobThread().object(replication, methodLists);
    }

    protected static void object(boolean replication, Set methodLists) {
        JacobVPU.activeJacobThread().object(replication,
                methodLists.toArray(new ChannelListener[methodLists.size()]));
    }

    protected static  T replication(ChannelListener methodList) {
        JacobVPU.activeJacobThread().object(true, methodList);
        return methodList.getChannel();
    }

    /**
     * Obtain a replicated channel broadcaster.
     *
     * @param channel target channel
     * @return replicated channel broadcaster
     */
    protected static  T replication(T channel) {
        // TODO: we should create a replicated wrapper here.
        return channel;
    }

    public Method getMethod(String methodName) {
        Set implementedMethods = getImplementedMethods();
        for (Method m : implementedMethods) {
            if (m.getName().equals(methodName)) {
                return m;
            }
        }
        throw new IllegalArgumentException("No such method \"" + methodName + "\"!");
    }

    public String toString() {
        return "";
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy