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

jadex.platform.service.email.EmailFetcherAgent Maven / Gradle / Ivy

package jadex.platform.service.email;

import java.util.List;

import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.service.annotation.Service;
import jadex.bridge.service.types.email.Email;
import jadex.commons.future.IFuture;
import jadex.commons.future.IIntermediateFuture;
import jadex.commons.future.IntermediateFuture;
import jadex.micro.annotation.Agent;

/**
 *  Agent that is responsible for fetching mails for one subscription.
 */
@Agent(autoprovide=true)
@Service
public class EmailFetcherAgent implements IEmailFetcherService
{
	/** The agent. */
	@Agent
	protected IInternalAccess agent;
	
	/**
	 *  Fetch emails for a subscription.
	 *  @param sub The subscription.
	 *  @return The emails.
	 */
	public IIntermediateFuture fetchEmails(SubscriptionInfo sub)
	{
		List emails = sub.getNewEmails();
		
		// Hack, needed because pool cannot be used (pro)
		agent.getComponentFeature(IExecutionFeature.class).scheduleStep(new IComponentStep()
		{
			public IFuture execute(IInternalAccess ia)
			{
//				System.out.println("kill: "+agent);
				agent.killComponent();
				return IFuture.DONE;
			}
		});
		
		return new IntermediateFuture(emails);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy