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

jadex.webservice.examples.rs.banking.BankingService Maven / Gradle / Ivy

Go to download

The Jadex web service applications package contains several example applications, benchmarks and testcases using web service integration.

There is a newer version: 4.0.267
Show newest version
package jadex.webservice.examples.rs.banking;

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

import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.service.annotation.OnStart;
import jadex.bridge.service.annotation.Service;
import jadex.bridge.service.annotation.ServiceComponent;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IIntermediateFuture;
import jadex.commons.future.IntermediateFuture;

/**
 * The Jadex implementation of the banking service.
 */
@Service
public class BankingService implements IBankingService
{
	/** The account data. */
	protected List data;
	
	/** The component. */
	@ServiceComponent
	protected IInternalAccess component;
	
	/**
	 *  Init with some data.
	 */
	//@ServiceStart
	@OnStart
	public void start()
	{
		data = new ArrayList();
		data.add("Statement 1");
		data.add("Statement 2");
		data.add("Statement 3");
	}
	
	/**
	 *  Get the account statement.
	 *  @param request The request.
	 *  @return The account statement.
	 */
	public IFuture getAccountStatement(Date begin, Date end)
	{
		System.out.println("getAccountStatement(Date begin, Date end)");
		AccountStatement as = new AccountStatement(data.toArray(new String[data.size()]), new Request(begin, end));
		return new Future(as);
	}

	
	/**
	 *  Get account statement.
	 *  @return The account statement.
	 */
	public IFuture getAccountStatement()
	{
		System.out.println("getAccountStatement()");
		AccountStatement as = new AccountStatement(data.toArray(new String[data.size()]), null);
		return new Future(as);
	}
	
	/**
	 *  Get an account statement.
	 *  @param request The request.
	 *  @return The account statement.
	 */
	public IFuture getAccountStatement(Request request)
	{
		System.out.println("getAccountStatement(Request request)");
		AccountStatement as = new AccountStatement(data.toArray(new String[data.size()]), request);
		return new Future(as);
	}
	
	/**
	 *  Subscribe for account statements.
	 *  @return Account statements whenever available.
	 */
	public IIntermediateFuture subscribeForAccountStatements(long delay, int max)
	{
		final IntermediateFuture ret = new IntermediateFuture();
		
		
		final int fmax = max>0? max: 5;
		final long fdelay = delay>0? delay: 1500;
//		ret.addIntermediateResult(new AccountStatement(new String[]{"initial"}, null));
		component.getFeature(IExecutionFeature.class).waitForDelay(fdelay, new IComponentStep()
		{
			int cnt = 0;
			public IFuture execute(IInternalAccess ia)
			{
				if(cnt++ addTransactionData(String data)
	{
		System.out.println("addTransactionData(String data)");
		this.data.add(data);
		return IFuture.DONE;
	}
	
	/**
	 *  Remove an account statement.
	 *  @param data The data.
	 */
	public IFuture removeTransactionData(String data)
	{
		System.out.println("removeTransactionData(String data)");
		this.data.remove(data);
		return IFuture.DONE;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy