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     */
022    package org.granite.ejb;
023    
024    import flex.messaging.messages.AsyncMessage;
025    import flex.messaging.messages.ErrorMessage;
026    import flex.messaging.messages.Message;
027    import org.granite.config.GraniteConfig;
028    import org.granite.config.flex.ServicesConfig;
029    import org.granite.context.GraniteContext;
030    import org.granite.gravity.*;
031    import org.granite.gravity.adapters.ServiceAdapter;
032    import org.granite.gravity.udp.UdpReceiverFactory;
033    import org.granite.messaging.jmf.SharedContext;
034    
035    import javax.ejb.Local;
036    import javax.ejb.Singleton;
037    
038    @Singleton(name="org.granite.ejb.Gravity")
039    @Local(Gravity.class)
040    public class GravityBean implements Gravity {
041    
042        private org.granite.gravity.Gravity gravity;
043    
044        public void setGravity(org.granite.gravity.Gravity gravity) {
045            this.gravity = gravity;
046        }
047    
048        private org.granite.gravity.Gravity getGravity() {
049            return gravity;
050        }
051    
052        ///////////////////////////////////////////////////////////////////////////
053        // Granite/Services configs access.
054    
055        public GravityConfig getGravityConfig() {
056            return getGravity().getGravityConfig();
057        }
058        public ServicesConfig getServicesConfig() {
059            return getGravity().getServicesConfig();
060        }
061        public GraniteConfig getGraniteConfig() {
062            return getGravity().getGraniteConfig();
063        }
064        public SharedContext getSharedContext() {
065            return getGravity().getSharedContext();
066        }
067    
068        ///////////////////////////////////////////////////////////////////////////
069        // Properties.
070    
071        public boolean isStarted() {
072            return getGravity().isStarted();
073        }
074    
075        ///////////////////////////////////////////////////////////////////////////
076        // Operations.
077    
078        public GraniteContext initThread(String sessionId, String clientType) {
079            return getGravity().initThread(sessionId, clientType);
080        }
081        public void releaseThread() {
082            getGravity().releaseThread();
083        }
084    
085        public ServiceAdapter getServiceAdapter(String messageType, String destinationId) {
086            return getGravity().getServiceAdapter(messageType, destinationId);
087        }
088    
089        public boolean hasUdpReceiverFactory() {
090            return getGravity().hasUdpReceiverFactory();
091        }
092        public UdpReceiverFactory getUdpReceiverFactory() {
093            return getGravity().getUdpReceiverFactory();
094        }
095    
096        public void start() throws Exception {
097            getGravity().start();
098        }
099        public void reconfigure(GravityConfig gravityConfig, GraniteConfig graniteConfig) {
100            getGravity().reconfigure(gravityConfig, graniteConfig);
101        }
102        public void stop() throws Exception {
103            getGravity().stop();
104        }
105        public void stop(boolean now) throws Exception {
106            getGravity().stop(now);
107        }
108    
109        public <C extends Channel> C getChannel(ChannelFactory<C> channelFactory, String channelId) {
110            return getGravity().getChannel(channelFactory, channelId);
111        }
112        public Channel removeChannel(String channelId, boolean timeout) {
113            return getGravity().removeChannel(channelId, timeout);
114        }
115        public boolean access(String channelId) {
116            return getGravity().access(channelId);
117        }
118        public void execute(AsyncChannelRunner runnable) {
119            getGravity().execute(runnable);
120        }
121        public boolean cancel(AsyncChannelRunner runnable) {
122            return getGravity().cancel(runnable);
123        }
124    
125        public Message handleMessage(ChannelFactory<?> channelFactory, Message message) {
126            return getGravity().handleMessage(channelFactory, message);
127        }
128        public Message handleMessage(ChannelFactory<?> channelFactory, Message message, boolean skipInterceptor) {
129            return getGravity().handleMessage(channelFactory, message, skipInterceptor);
130        }
131        public Message publishMessage(AsyncMessage message) {
132            return publishMessage(null, message);
133        }
134        public Message publishMessage(Channel fromChannel, AsyncMessage message) {
135            if (getGravity() == null)
136                return new ErrorMessage(message, new IllegalStateException("Gravity EJB not yet ready"));
137    
138            return getGravity().publishMessage(fromChannel, message);
139        }
140    
141    }