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

org.openl.util.ce.impl.SequenceActivity Maven / Gradle / Ivy

There is a newer version: 5.19.9
Show newest version
package org.openl.util.ce.impl;

import java.util.ArrayList;
import java.util.List;

import org.openl.util.ce.IActivity;
import org.openl.util.ce.ICallableActivity;
import org.openl.util.ce.IInvokableActivity;
import org.openl.util.ce.IScheduledActivity;
import org.openl.vm.IRuntimeEnv;

public class SequenceActivity implements IScheduledActivity {

	int id;
	int precedentSize;

	List dependents = new ArrayList();
	IScheduledActivity[] activities;
	boolean isInvokable;

	public SequenceActivity(IScheduledActivity[] activities, boolean isInvokable) {
		this.activities = activities;
		this.isInvokable = isInvokable;

	}

	@Override
	public IActivity activity() {
		if (isInvokable)
			return invokableActivity();
		return callableActivity();
	}

	private ICallableActivity callableActivity() {
		return new ICallableActivity() {

			@Override
			public List dependsOn() {
				return null;
			}

			@Override
			public long duration() {
				return 0;
			}


			@Override
			public Object call() throws Exception {
				for (int i = 0; i < activities.length; i++) {
					((ICallableActivity) activities[i].activity()).call();
				}

				return null;
			}
		};
	}

	public IInvokableActivity invokableActivity() {
		return new IInvokableActivity() {

			@Override
			public List dependsOn() {
				return null;
			}

			@Override
			public long duration() {
				return 0;
			}

			@Override
			public Object invoke(Object target, Object[] params, IRuntimeEnv env) {
				for (int i = 0; i < activities.length; i++) {
					((IInvokableActivity) activities[i].activity()).invoke(
							target, params, env);
				}

				return null;
			}
		};

	}

	@Override
	public long getCriticalDistance() {
		return 0;
	}

	@Override
	public boolean isOnCriticalPath() {
		return false;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public List getDependents() {
		return dependents;
	}

	public void setDependents(List dependents) {
		this.dependents = dependents;
	}

	public int getPrecedentSize() {
		return precedentSize;
	}

	public void setPrecedentSize(int precedentSize) {
		this.precedentSize = precedentSize;
	}

}