001    /**
002     *   GRANITE DATA SERVICES
003     *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004     *
005     *   This file is part of Granite Data Services.
006     *
007     *   Granite Data Services is free software; you can redistribute it and/or modify
008     *   it under the terms of the GNU Library General Public License as published by
009     *   the Free Software Foundation; either version 2 of the License, or (at your
010     *   option) any later version.
011     *
012     *   Granite Data Services is distributed in the hope that it will be useful, but
013     *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014     *   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015     *   for more details.
016     *
017     *   You should have received a copy of the GNU Library General Public License
018     *   along with this library; if not, see <http://www.gnu.org/licenses/>.
019     */
020    package org.granite.client.messaging.channel;
021    
022    import java.net.URI;
023    
024    import org.granite.client.configuration.Configuration;
025    import org.granite.client.messaging.channel.amf.AMFMessagingChannel;
026    import org.granite.client.messaging.channel.amf.AMFRemotingChannel;
027    import org.granite.client.messaging.transport.Transport;
028    import org.granite.client.platform.Platform;
029    import org.granite.util.ContentType;
030    
031    /**
032     * @author Franck WOLFF
033     */
034    public class AMFChannelFactory extends AbstractChannelFactory {
035        
036            private final Configuration defaultConfiguration;
037            
038            public AMFChannelFactory() {
039                    this(null, null, null, null);
040            }
041            
042            public AMFChannelFactory(Object context) {
043                    this(context, null, null, null);
044            }
045            
046            public AMFChannelFactory(Object context, Configuration defaultConfiguration) {
047                    this(context, null, null, defaultConfiguration);
048            }
049    
050            public AMFChannelFactory(Object context, Transport remotingTransport, Transport messagingTransport) {
051                    this(context, remotingTransport, messagingTransport, null);
052            }
053    
054            public AMFChannelFactory(Object context, Transport remotingTransport, Transport messagingTransport, Configuration defaultConfiguration) {
055                    super(ContentType.AMF, context, remotingTransport, messagingTransport);
056                    
057                    this.defaultConfiguration = (defaultConfiguration != null ? defaultConfiguration : Platform.getInstance().newConfiguration());
058                    this.aliasRegistry = this.defaultConfiguration.getGraniteConfig().getAliasRegistry();
059            }
060    
061            @Override
062            public AMFRemotingChannel newRemotingChannel(String id, URI uri) {
063                    return newRemotingChannel(id, uri, RemotingChannel.DEFAULT_MAX_CONCURRENT_REQUESTS);
064            }
065    
066            @Override
067            public AMFRemotingChannel newRemotingChannel(String id, URI uri, int maxConcurrentRequests) {
068                    return new AMFRemotingChannel(getRemotingTransport(), defaultConfiguration, id, uri, maxConcurrentRequests);
069            }
070    
071            @Override
072            public AMFMessagingChannel newMessagingChannel(String id, URI uri) {
073                    return new AMFMessagingChannel(getMessagingTransport(), defaultConfiguration, id, uri);
074            }
075            
076            public Configuration getDefaultConfiguration() {
077                    return defaultConfiguration;
078            }
079    }