
org.objectweb.dream.channel.ChannelInOutImpl 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 java.util.HashMap;
import java.util.Map;
import org.objectweb.dream.Push;
import org.objectweb.dream.PushException;
import org.objectweb.dream.dreamannotation.DreamComponent;
import org.objectweb.dream.dreamannotation.DreamMonolog;
import org.objectweb.dream.message.Message;
import org.objectweb.dream.protocol.ExportException;
import org.objectweb.dream.protocol.IncomingPush;
import org.objectweb.dream.protocol.messagePassing.MessagePassingProtocol;
import org.objectweb.dream.util.Error;
import org.objectweb.dream.util.LoggerUtil;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.fraclet.annotation.annotations.type.LifeCycleType;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.fraclet.annotation.annotations.Attribute;
import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
import org.objectweb.fractal.fraclet.annotation.annotations.LifeCycle;
import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
import org.objectweb.fractal.fraclet.annotation.annotations.Requires;
import org.objectweb.fractal.fraclet.annotation.annotations.Service;
import org.objectweb.util.monolog.api.Logger;
/**
* ChannelInOut implementation.
*/
@DreamComponent(controllerDesc = "dreamPrimitive", needAsyncStart = true)
@Provides(interfaces = { @Interface(name = "in-push", signature = Push.class),
@Interface(name = "incoming-in-push", signature = IncomingPush.class) })
public class ChannelInOutImpl extends ChannelOutImpl implements IncomingPush {
/**
* The name of the chunk that should be added in every received messages. If
* null
or equals to "null"
, no chunk will be
* added
*/
@Attribute(argument = "fromChunkName")
private String fromChunkName;
// ------------------------------------------------------------------------
// ---
// Client interfaces
// ------------------------------------------------------------------------
// ---
@Requires(name = "out-push")
private Push outPushItf;
// ------------------------------------------------------------------------
// --
// Services interfaces
// ------------------------------------------------------------------------
// --
/**
* Component reference
*/
@Service
private Component weaveableC;
/**
* Logger of the component
*/
@DreamMonolog()
protected Logger logger;
/**
* @see IncomingPush#incomingPush(Message)
*/
public void incomingPush(Message message) throws PushException {
outPushItf.push(message);
}
/**
* @see IncomingPush#incomingClosed(Object, Exception)
*/
public void incomingClosed(Object outgoingPush, Exception exception) {
// do nothing.
}
// ------------------------------------------------------------------------
// ---
// Overridden methods of LifeCycle
// ------------------------------------------------------------------------
// ---
/**
* Export the channel
*/
@LifeCycle(on = LifeCycleType.START)
protected void startFcHandler() throws IllegalLifeCycleException {
LoggerUtil.start(logger);
try {
Map hints = new HashMap();
hints.put(MessagePassingProtocol.FROM_CHUNK_NAME, fromChunkName);
lowerOutgoingPush = lowerProtocolItf.export((IncomingPush) weaveableC
.getFcInterface(INCOMING_IN_PUSH_ITF_NAME), hints);
} catch (ExportException e) {
throw new IllegalLifeCycleException("Unable to export access point : " + e.getMessage());
} catch (NoSuchInterfaceException e) {
Error.bug(logger, e);
}
LoggerUtil.end(logger);
}
/**
* Reset {@link #lowerOutgoingPush}
*/
@LifeCycle(on = LifeCycleType.STOP)
protected void stopFcHandler() throws IllegalLifeCycleException {
lowerOutgoingPush = null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy