<commit_before>/*
 * Copyright 2010 the original author or authors.
 * Copyright 2010 SorcerSoft.org.
 *  
 * 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.
 */

package sorcer.core.provider.exerter;

import net.jini.core.lookup.ServiceID;
import net.jini.core.transaction.Transaction;
import net.jini.core.transaction.TransactionException;
import net.jini.core.transaction.server.TransactionManager;
import org.dancres.blitz.jini.lockmgr.LockResult;
import org.dancres.blitz.jini.lockmgr.MutualExclusion;
import sorcer.core.SorcerConstants;
import sorcer.core.context.ControlContext;
import sorcer.core.context.ServiceContext;
import sorcer.core.context.ThrowableTrace;
import sorcer.core.context.model.ent.Entry;
import sorcer.core.context.model.par.Par;
import sorcer.core.deploy.ServiceDeployment;
import sorcer.core.dispatch.*;
import sorcer.core.provider.*;
import sorcer.core.signature.NetSignature;
import sorcer.core.signature.ServiceSignature;
import sorcer.ext.ProvisioningException;
import sorcer.jini.lookup.ProviderID;
import sorcer.service.*;
import sorcer.service.Exec.State;
import sorcer.service.Strategy.Access;
import sorcer.service.modeling.ModelingTask;
import sorcer.service.txmgr.TransactionManagerAccessor;
import sorcer.util.ProviderLookup;
import sorcer.util.Sorcer;

import java.rmi.RemoteException;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.logging.Logger;

/**
 * @author <NAME>
 */
@SuppressWarnings("rawtypes")
public class ServiceShell implements Shell, Service, Exerter, Callable {
	protected final static Logger logger = Logger.getLogger(ServiceShell.class
			.getName());

	private ServiceExertion exertion;
	private Transaction transaction;
	private static MutualExclusion locker;

	public ServiceShell() {
	}

	public ServiceShell(Exertion xrt) {
		exertion = (ServiceExertion) xrt;
	}

	public ServiceShell(Exertion xrt, Transaction txn) {
		exertion = (ServiceExertion) xrt;
		transaction = txn;

	}

	// a refrence to a provider running this service bean
	private Provider provider;

	public void init(Provider provider) {
		this.provider = provider;
	}
	
	public <T extends Mogram> T  exert(Arg... entries) throws TransactionException,
			ExertionException, RemoteException {
		return exert((Transaction) null, (String) null, entries);
	}

	/* (non-Javadoc)
	 * @see sorcer.service.Exerter#exert(sorcer.service.Exertion, sorcer.service.Parameter[])
	 */
	@Override
	public Exertion exert(Exertion xrt, Arg... entries)
			throws TransactionException, ExertionException, RemoteException {
		try {
			xrt.substitute(entries);
		} catch (Exception e) {
			throw new ExertionException(e);
		}
		return exert(xrt, (Transaction) null, (String) null);
	}
	
	/* (non-Javadoc)
	 * @see sorcer.service.Exerter#exert(sorcer.service.Exertion, net.jini.core.transaction.Transaction, sorcer.service.Parameter[])
	 */
	@Override
	public Exertion exert(Exertion xrt, Transaction txn, Arg... entries)
			throws TransactionException, ExertionException, RemoteException {
		try {
			xrt.substitute(entries);
		} catch (Exception e) {
			throw new ExertionException(e);
		}
		transaction = txn;
		return exert(xrt, txn, (String) null);
	}

	public  <T extends Mogram> T exert(String providerName) throws TransactionException,
			ExertionException, RemoteException {
		return exert(null, providerName);
	}

	@Override
	public Exertion service(Mogram exertion, Transaction txn) throws TransactionException, ExertionException, RemoteException {
		return exert((Exertion)exertion, txn);
	}

	@Override
	public Exertion service(Mogram exertion) throws TransactionException, ExertionException, RemoteException {
		return exert((Exertion)exertion);
	}

	public  <T extends Mogram> T exert(T xrt, Transaction txn, String providerName)
			throws TransactionException, ExertionException, RemoteException {
		this.exertion = (ServiceExertion) xrt;
		transaction = txn;
		return exert(txn, providerName);
	}
	
	
	public <T extends Mogram> T  exert(Transaction txn, String providerName, Arg... entries)
			throws TransactionException, ExertionException, RemoteException {
		try {
			exertion.selectFidelity(entries);
			Exertion xrt = postProcessExertion(exert0(txn, providerName,
					entries));
			if (exertion.isProxy()) {
				exertion.setContext(xrt.getDataContext());
				exertion.setControlContext((ControlContext)xrt.getControlContext());
				if (exertion.isCompound()) {
					((CompoundExertion) exertion)
							.setMograms(((CompoundExertion) xrt)
									.getMograms());
				}

				return (T) exertion;
			} else {
				return (T) xrt;
			}
		} catch (ContextException e) {
			throw new ExertionException(e);
		}
	}
	
	private void initExecState(Arg... entries) throws ContextException, RemoteException {
		Context argCxt = null;
		for (Arg arg : entries) {
			if (arg instanceof Context && ((Context)arg).size() > 0) {
				argCxt = (Context)arg;
			}
		}
		if (exertion instanceof Block) {<commit_msg>Fixing problem with setting initial state - appeared in mstc-eng-open tests<commit_after>/*
 * Copyright 2010 the original author or authors.
 * Copyright 2010 SorcerSoft.org.
 *  
 * 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.
 */

package sorcer.core.provider.exerter;

import net.jini.core.lookup.ServiceID;
import net.jini.core.transaction.Transaction;
import net.jini.core.transaction.TransactionException;
import net.jini.core.transaction.server.TransactionManager;
import org.dancres.blitz.jini.lockmgr.LockResult;
import org.dancres.blitz.jini.lockmgr.MutualExclusion;
import sorcer.core.SorcerConstants;
import sorcer.core.context.ControlContext;
import sorcer.core.context.ServiceContext;
import sorcer.core.context.ThrowableTrace;
import sorcer.core.context.model.ent.Entry;
import sorcer.core.context.model.par.Par;
import sorcer.core.deploy.ServiceDeployment;
import sorcer.core.dispatch.*;
import sorcer.core.provider.*;
import sorcer.core.signature.NetSignature;
import sorcer.core.signature.ServiceSignature;
import sorcer.ext.ProvisioningException;
import sorcer.jini.lookup.ProviderID;
import sorcer.service.*;
import sorcer.service.Exec.State;
import sorcer.service.Strategy.Access;
import sorcer.service.modeling.ModelingTask;
import sorcer.service.txmgr.TransactionManagerAccessor;
import sorcer.util.ProviderLookup;
import sorcer.util.Sorcer;

import java.rmi.RemoteException;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.logging.Logger;

/**
 * @author <NAME>
 */
@SuppressWarnings("rawtypes")
public class ServiceShell implements Shell, Service, Exerter, Callable {
	protected final static Logger logger = Logger.getLogger(ServiceShell.class
			.getName());

	private ServiceExertion exertion;
	private Transaction transaction;
	private static MutualExclusion locker;

	public ServiceShell() {
	}

	public ServiceShell(Exertion xrt) {
		exertion = (ServiceExertion) xrt;
	}

	public ServiceShell(Exertion xrt, Transaction txn) {
		exertion = (ServiceExertion) xrt;
		transaction = txn;

	}

	// a refrence to a provider running this service bean
	private Provider provider;

	public void init(Provider provider) {
		this.provider = provider;
	}
	
	public <T extends Mogram> T  exert(Arg... entries) throws TransactionException,
			ExertionException, RemoteException {
		return exert((Transaction) null, (String) null, entries);
	}

	/* (non-Javadoc)
	 * @see sorcer.service.Exerter#exert(sorcer.service.Exertion, sorcer.service.Parameter[])
	 */
	@Override
	public Exertion exert(Exertion xrt, Arg... entries)
			throws TransactionException, ExertionException, RemoteException {
		try {
			xrt.substitute(entries);
		} catch (Exception e) {
			throw new ExertionException(e);
		}
		return exert(xrt, (Transaction) null, (String) null);
	}
	
	/* (non-Javadoc)
	 * @see sorcer.service.Exerter#exert(sorcer.service.Exertion, net.jini.core.transaction.Transaction, sorcer.service.Parameter[])
	 */
	@Override
	public Exertion exert(Exertion xrt, Transaction txn, Arg... entries)
			throws TransactionException, ExertionException, RemoteException {
		try {
			xrt.substitute(entries);
		} catch (Exception e) {
			throw new ExertionException(e);
		}
		transaction = txn;
		return exert(xrt, txn, (String) null);
	}

	public  <T extends Mogram> T exert(String providerName) throws TransactionException,
			ExertionException, RemoteException {
		return exert(null, providerName);
	}

	@Override
	public Exertion service(Mogram exertion, Transaction txn) throws TransactionException, ExertionException, RemoteException {
		return exert((Exertion)exertion, txn);
	}

	@Override
	public Exertion service(Mogram exertion) throws TransactionException, ExertionException, RemoteException {
		return exert((Exertion)exertion);
	}

	public  <T extends Mogram> T exert(T xrt, Transaction txn, String providerName)
			throws TransactionException, ExertionException, RemoteException {
		this.exertion = (ServiceExertion) xrt;
		transaction = txn;
		return exert(txn, providerName);
	}
	
	
	public <T extends Mogram> T  exert(Transaction txn, String providerName, Arg... entries)
			throws TransactionException, ExertionException, RemoteException {
		try {
			exertion.selectFidelity(entries);
			Exertion xrt = postProcessExertion(exert0(txn, providerName,
					entries));
			if (exertion.isProxy()) {
				exertion.setContext(xrt.getDataContext());
				exertion.setControlContext((ControlContext)xrt.getControlContext());
				if (exertion.isCompound()) {
					((CompoundExertion) exertion)
							.setMograms(((CompoundExertion) xrt)
									.getMograms());
				}

				return (T) exertion;
			} else {
				return (T) xrt;
			}
		} catch (ContextException e) {
			throw new ExertionException(e);
		}
	}
	
	private void initExecState(Arg... entries) throws ContextException, RemoteException {
		Context argCxt = null;
		if (entries!=null) {
			for (Arg arg : entries) {
				if (arg instanceof Context && ((Context)arg).size() > 0) {
					argCxt = (Context)arg;
				}
			}
		}
		if (exertion instanceof Block) {
{'fraction_non_alphanumeric': 0.10226860254083485, 'fraction_numerical': 0.002540834845735027, 'mean_word_length': 4.695607235142119, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6892698', 'n_tokens_mistral': 3673, 'n_tokens_neox': 3335, 'n_words': 867}