001/**
002 *   GRANITE DATA SERVICES
003 *   Copyright (C) 2006-2014 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.ejb;
023
024import java.security.Principal;
025import java.util.List;
026import java.util.Set;
027
028import javax.ejb.Local;
029import javax.ejb.Singleton;
030
031import org.granite.config.GraniteConfig;
032import org.granite.config.flex.ServicesConfig;
033import org.granite.gravity.Channel;
034import org.granite.gravity.GravityConfig;
035
036import flex.messaging.messages.AsyncMessage;
037import flex.messaging.messages.ErrorMessage;
038import flex.messaging.messages.Message;
039
040@Singleton(name="org.granite.ejb.Gravity")
041@Local(Gravity.class)
042public class GravityBean implements Gravity {
043
044    private org.granite.gravity.Gravity gravity;
045
046    public void setGravity(org.granite.gravity.Gravity gravity) {
047        this.gravity = gravity;
048    }
049
050    private org.granite.gravity.Gravity getGravity() {
051        return gravity;
052    }
053
054    ///////////////////////////////////////////////////////////////////////////
055    // Granite/Services configs access.
056
057    public GravityConfig getGravityConfig() {
058        return getGravity().getGravityConfig();
059    }
060    public ServicesConfig getServicesConfig() {
061        return getGravity().getServicesConfig();
062    }
063    public GraniteConfig getGraniteConfig() {
064        return getGravity().getGraniteConfig();
065    }
066
067    ///////////////////////////////////////////////////////////////////////////
068    // Properties.
069
070    public boolean isStarted() {
071        return getGravity().isStarted();
072    }
073
074    ///////////////////////////////////////////////////////////////////////////
075    // Operations.
076
077    @Override
078    public List<Channel> getConnectedChannels() {
079        return getGravity().getConnectedChannels();
080    }
081    @Override
082    public Set<Principal> getConnectedUsers() {
083        return getGravity().getConnectedUsers();
084    }
085    @Override
086    public List<Channel> getConnectedChannelsByDestination(String destination) {
087        return getGravity().getConnectedChannelsByDestination(destination);
088    }
089    @Override
090    public Set<Principal> getConnectedUsersByDestination(String destination) {
091        return getGravity().getConnectedUsersByDestination(destination);
092    }
093    @Override
094    public List<Channel> findConnectedChannelsByUser(String name) {
095        return getGravity().findConnectedChannelsByUser(name);
096    }
097    @Override
098    public Channel findConnectedChannelByClientId(String clientId) {
099        return getGravity().findConnectedChannelByClientId(clientId);
100    }
101    @Override
102    public Channel findCurrentChannel(String destination) {
103        return getGravity().findCurrentChannel(destination);
104    }
105    
106    public void start() throws Exception {
107        getGravity().start();
108    }
109    public void reconfigure(GravityConfig gravityConfig, GraniteConfig graniteConfig) {
110        getGravity().reconfigure(gravityConfig, graniteConfig);
111    }
112    public void stop() throws Exception {
113        getGravity().stop();
114    }
115    public void stop(boolean now) throws Exception {
116        getGravity().stop(now);
117    }
118
119    public Message handleMessage(Message message) {
120        return getGravity().handleMessage(message);
121    }
122    public Message handleMessage(Message message, boolean skipInterceptor) {
123        return getGravity().handleMessage(message, skipInterceptor);
124    }
125    public Message publishMessage(AsyncMessage message) {
126        return publishMessage(null, message);
127    }
128    public Message publishMessage(Channel fromChannel, AsyncMessage message) {
129        if (getGravity() == null)
130            return new ErrorMessage(message, new IllegalStateException("Gravity EJB not yet ready"));
131
132        return getGravity().publishMessage(fromChannel, message);
133    }
134    public Message sendRequest(Channel fromChannel, AsyncMessage message) {
135        if (getGravity() == null)
136            return new ErrorMessage(message, new IllegalStateException("Gravity not initialized"));
137
138        return getGravity().sendRequest(fromChannel, message);
139    }
140
141}