001/**
002 *   GRANITE DATA SERVICES
003 *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004 *
005 *   This file is part of the Granite Data Services Platform.
006 *
007 *   Granite Data Services is free software; you can redistribute it and/or
008 *   modify it under the terms of the GNU Lesser General Public
009 *   License as published by the Free Software Foundation; either
010 *   version 2.1 of the License, or (at your option) any later version.
011 *
012 *   Granite Data Services is distributed in the hope that it will be useful,
013 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015 *   General Public License for more details.
016 *
017 *   You should have received a copy of the GNU Lesser General Public
018 *   License along with this library; if not, write to the Free Software
019 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020 *   USA, or see <http://www.gnu.org/licenses/>.
021 */
022package org.granite.gravity;
023
024import org.granite.config.GraniteConfig;
025import org.granite.config.ShutdownListener;
026import org.granite.config.flex.ServicesConfig;
027import org.granite.context.GraniteContext;
028import org.granite.gravity.adapters.ServiceAdapter;
029import org.granite.gravity.udp.UdpReceiverFactory;
030
031import flex.messaging.messages.AsyncMessage;
032import flex.messaging.messages.Message;
033import org.granite.messaging.jmf.SharedContext;
034
035/**
036 * @author Franck WOLFF
037 */
038public interface Gravity extends ShutdownListener {
039
040    ///////////////////////////////////////////////////////////////////////////
041    // Constants.
042
043    public static final String RECONNECT_INTERVAL_MS_KEY = "reconnect-interval-ms";
044    public static final String RECONNECT_MAX_ATTEMPTS_KEY = "reconnect-max-attempts";
045    public static final String ENCODE_MESSAGE_BODY_KEY = "encode-message-body";
046    
047    public static final String BYTEARRAY_BODY_HEADER = "GDS_BYTEARRAY_BODY";    
048
049    ///////////////////////////////////////////////////////////////////////////
050    // Granite/Services configs access.
051
052    public GravityConfig getGravityConfig();
053    public ServicesConfig getServicesConfig();
054    public GraniteConfig getGraniteConfig();
055    public SharedContext getSharedContext();
056
057    ///////////////////////////////////////////////////////////////////////////
058    // UDP support.
059    
060    public boolean hasUdpReceiverFactory();
061    public UdpReceiverFactory getUdpReceiverFactory();
062
063    ///////////////////////////////////////////////////////////////////////////
064    // Properties.
065
066        public boolean isStarted();
067
068    ///////////////////////////////////////////////////////////////////////////
069    // Operations.
070
071    public GraniteContext initThread(String sessionId, String clientType);
072    public void releaseThread();
073        
074        public ServiceAdapter getServiceAdapter(String messageType, String destinationId);
075        
076    public void start() throws Exception;
077    public void reconfigure(GravityConfig gravityConfig, GraniteConfig graniteConfig);
078    public void stop() throws Exception;
079    public void stop(boolean now) throws Exception;
080
081    public <C extends Channel> C getChannel(ChannelFactory<C> channelFactory, String clientId);
082    public Channel removeChannel(String clientId, boolean timeout);
083    public boolean access(String clientId);
084    public void execute(AsyncChannelRunner runnable);
085    public boolean cancel(AsyncChannelRunner runnable);
086
087    public Message handleMessage(ChannelFactory<? extends Channel> channelFactory, Message message);
088    public Message handleMessage(ChannelFactory<? extends Channel> channelFactory, Message message, boolean skipInterceptor);
089    public Message publishMessage(AsyncMessage message);
090    public Message publishMessage(Channel fromChannel, AsyncMessage message);
091}