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

org.objectweb.dream.channel.DestinationResolverChunkBased 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): 
 */

package org.objectweb.dream.channel;

import org.objectweb.dream.PushException;
import org.objectweb.dream.dreamannotation.DreamComponent;
import org.objectweb.dream.message.Message;
import org.objectweb.dream.message.MessageManagerType;
import org.objectweb.dream.protocol.ExportIdentifier;
import org.objectweb.dream.protocol.ExportIdentifierChunk;
import org.objectweb.fractal.fraclet.annotation.annotations.Attribute;
import org.objectweb.fractal.fraclet.annotation.annotations.Requires;

/**
 * Destination resolver that retrieves {@link ExportIdentifier} if a {@link
 * org.objectweb.dream.protocol.ExportIdentifierChunk} is in the message.
 */
@DreamComponent(controllerDesc = "activeDreamUnstoppablePrimitive")
public class DestinationResolverChunkBased implements DestinationResolver {

    // ------------------------------------------------------------------------
    // ---
    // Attribute fields
    // ------------------------------------------------------------------------
    // ---

    /**
     * The name of the chunks that contains the destination identification of
     * the message
     */
    @Attribute(argument = "destinationChunkName")
    protected String destinationChunkName;

    /**
     * true if the destination chunk must be deleted from the
     * message. The default value is true
     */
    @Attribute(argument = "deleteChunk")
    protected boolean deleteChunk = true;

    // ------------------------------------------------------------------------
    // ---
    // Client interfaces
    // ------------------------------------------------------------------------
    // ---

    @Requires(name = "message-manager")
    protected MessageManagerType messageManagerItf;

    // ------------------------------------------------------------------------
    // ---
    // Implementation of Destination Resolver interface
    // ------------------------------------------------------------------------
    // ---

    /**
     * Return the {@link ExportIdentifier} contained in the {@link
     * ExportIdentifierChunk}. This chunk, included in the message
     * given as parameter, is identified by its {@link #destinationChunkName}.
     * 
Depending on the {@link #deleteChunk} value, the chunk is removed * from the message. * * @param message * a message that MUST contains an {@link ExportIdentifierChunk} * identified by its {@link #destinationChunkName}. * @return The destination {@link ExportIdentifier identifier} of the * message. * @throws PushException * if the chunk can't be found. * @see DestinationResolver#resolveDestination(Message) */ public ExportIdentifier resolveDestination(Message message) throws PushException { ExportIdentifierChunk chunk = messageManagerItf.getChunk(message, destinationChunkName); if (chunk == null) { throw new PushException("Unable to find \"" + destinationChunkName + "\" chunk in message"); } ExportIdentifier exportIdentifier = chunk.getExportIdentifier(); if (deleteChunk) { chunk = messageManagerItf.removeChunk(message, destinationChunkName); messageManagerItf.deleteChunk(chunk); } return exportIdentifier; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy