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

org.dihedron.patterns.bus.Task Maven / Gradle / Ivy

Go to download

Base set of functionalities, including simple utility classes and more complex patterns.

The newest version!
/**
 * Copyright (c) 2012-2014, Andrea Funto'. All rights reserved. See LICENSE for details.
 */ 
package org.dihedron.patterns.bus;

import java.util.concurrent.Callable;

import org.dihedron.core.License;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * The common base task for internal bus tasks.
 * 
 * @author Andrea Funto'
 */
@License
class Task implements Callable {
	
	/**
	 * The logger.
	 */
	private static final Logger logger = LoggerFactory.getLogger(Task.class);
	
	/**
	 * The destination to which the message must be delivered.
	 */
	protected Destination destination;
	
	/**
	 * The message to dispatch.
	 */
	protected M message;
	
	/**
	 * Constructor.
	 *
	 * @param destination
	 *   the destination to which the message must be delivered.
	 * @param message
	 *   the message to dispatch.
	 */
	Task(Destination destination, M message) {
		this.destination = destination;
		this.message = message;
	}
	
	/**
	 * @see java.util.concurrent.Callable#call()
	 */
	@Override
	public Void call() throws Exception {
		logger.trace("dispatching message {} to destination {} in thread {}", message, destination, Thread.currentThread().getId());
		destination.onMessage(message);
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy