
org.objectweb.dream.router.ChunkNameBasedRouter Maven / Gradle / Ivy
/**
* Dream
* Copyright (C) 2003-2004 INRIA Rhone-Alpes
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact : [email protected]
*
* Initial developer(s): Matthieu Leclercq
* Contributor(s): Romain Lenglet
*/
package org.objectweb.dream.router;
import org.objectweb.dream.Push;
import org.objectweb.dream.PushException;
import org.objectweb.dream.dreamannotation.DreamComponent;
import org.objectweb.dream.message.AbstractChunk;
import org.objectweb.dream.message.Message;
import org.objectweb.dream.message.MessageManagerType;
import org.objectweb.fractal.fraclet.annotation.annotations.Attribute;
import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
import org.objectweb.fractal.fraclet.annotation.annotations.Requires;
/**
* A basic router implementation with two outputs :
* out-push-with-chunk
and out-push-without-chunk
. The
* first one is used if pushed messages contain a specified chunk name, the
* second one is used otherwise. The chunk name to check is specified as
* attribute.
*/
@DreamComponent(controllerDesc = "dreamPrimitive")
@Provides(interfaces = @Interface(name = "in-push", signature = Push.class))
public class ChunkNameBasedRouter implements Push {
/**
* The name of client interface used to push messages with the specified
* chunk name.
*/
public static final String OUTPUSH_WITH_CHUNK_ITF_NAME = "out-push-with-chunk";
/**
* The name of client interface used to push messages without the specified
* chunk name.
*/
public static final String OUTPUSH_WITHOUT_CHUNK_ITF_NAME = "out-push-without-chunk";
// ------------------------------------------------------------------------
// ---
// Client interfaces
// ------------------------------------------------------------------------
// ---
/** The interface used to push messages with the specified chunk name. */
@Requires(name = OUTPUSH_WITH_CHUNK_ITF_NAME)
protected Push outPushWithChunkItf;
/** The interface used to push messages without the specified chunk name. */
@Requires(name = OUTPUSH_WITHOUT_CHUNK_ITF_NAME)
protected Push outPushWithoutChunkItf;
@Requires(name = "message-manager")
protected MessageManagerType messageManagerItf;
// ------------------------------------------------------------------------
// ---
// Attribute fields
// ------------------------------------------------------------------------
// ---
/** the chunk name to test */
@Attribute(argument = "chunkName")
protected String chunkName;
/**
* @see Push#push(Message)
*/
@SuppressWarnings("unchecked")
public void push(Message message) throws PushException {
AbstractChunk chunk = messageManagerItf.getChunk(message, chunkName);
if (chunk == null) {
outPushWithoutChunkItf.push(message);
} else {
outPushWithChunkItf.push(message);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy