Beispiel #1
0
        /// <summary>Add the <code>StartChannelListener</code> for the specified URI.</summary>
        /// <param name="profile"></param>
        /// <param name="listener"></param>
        /// <returns>the previously registered <code>StartChannelListener</code></returns>
        public virtual IStartChannelListener addStartChannelListener(string profile, IStartChannelListener listener, SessionTuningProperties tuning)
        {
            lock (this)
            {
                // Replace semantics - change this if we want to prevent clobbering.
                IStartChannelListener temp = null;

                if (profileListeners[profile] != null)
                {
                    temp = ((InternalProfile) profileListeners[profile]).listener;
                }

                InternalProfile tempProfile = new InternalProfile(this);

                tempProfile.listener = listener;

                tempProfile.tuning = tuning;

                profileListeners[profile] = tempProfile;

                return temp;
            }
        }
Beispiel #2
0
        /// <summary>Returns the <code>StartChannelListener</code> for the specified URI.</summary>
        /// <param name="uri"></param>
        public virtual IStartChannelListener getStartChannelListener(SessionTuningProperties tuning, string uri)
        {
            InternalProfile profile = (InternalProfile) profileListeners[uri];

            if (profile == null)
            {
                return null;
            }

            // if there are no qualifications, then just return the listener
            if (profile.tuning == null || profile.tuning.Empty)
            {
                return ((InternalProfile) profileListeners[uri]).listener;
            }

            // so the profile requires something, but if the session doesn't
            // have anything, then return null
            if (tuning == null)
            {
                log.debug("Session does not have any tuning properties");
                return null;
            }

            // if the profile requires any of the standard properties, then
            // make sure they are set on the session before returning the listener
            int i = 0;

            for (i = 0; i < SessionTuningProperties.STANDARD_PROPERTIES.Length; i++)
            {
                if ((profile.tuning.getProperty(SessionTuningProperties.STANDARD_PROPERTIES[i]) != null) && (tuning.getProperty(SessionTuningProperties.STANDARD_PROPERTIES[i]) == null))
                {
                    if (log.isDebugEnabled())
                    {
                        log.debug("Session does not have tuning property " + SessionTuningProperties.STANDARD_PROPERTIES[i]);
                    }
                    return null;
                }
            }

            // all the ones the profile requested must be there so we return the
            // listener
            return ((InternalProfile) profileListeners[uri]).listener;
        }
Beispiel #3
0
        /// <summary>Method complete</summary>
        /// <exception cref="BEEPException" />
        public virtual void complete(IChannel channel, SessionCredential localCred, SessionCredential peerCred, SessionTuningProperties tuning, ProfileRegistry registry, object argument)
        {
            try
            {
                log.debug("TuningProfile.complete");

                SessionImpl s = (SessionImpl) channel.Session;

                s.reset(localCred, peerCred, tuning, registry, argument);
                tuningChannels.Remove(channel);
            }
            catch (System.Exception x)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                abort(new BEEPError(BEEPStatusCode.REQUESTED_ACTION_ABORTED, "TuningProfile.complete failure\n" + x.Message), channel);
            }
        }
Beispiel #4
0
 /// <summary>Method reset
 /// </summary>
 /// <exception cref="BEEPException" />
 protected internal static ISession reset(ISession session, SessionCredential localCred, SessionCredential peerCred, SessionTuningProperties tuning, ProfileRegistry registry, object argument)
 {
     return ((SessionImpl) session).reset(localCred, peerCred, tuning, registry, argument);
 }
Beispiel #5
0
        /// <param name="sock">the Socket for this TCPConnection</param>
        /// <param name="registry">the ProfileRegistry (set of profiles) to be used on
        /// this Session</param>
        /// <param name="firstChannel">the integer indicating the
        /// ordinality for this Peer, which determines whether Channels
        /// started by this peer have odd or even numbers.</param>
        /// <param name="localCred"></param>
        /// <param name="peerCred"></param>
        /// <remarks>
        /// The hack-ish part of this is the credential parameter.  Here's
        /// the deal.  (1) TCPSessionCreator has public methods that don't
        /// expose the credential (2) Therefore if it's called by the User,
        /// it can only have a null credential.  (3) If it's called via a
        /// Tuning Profile reset though, it can have a real value.  (4)
        /// When that's the case, we call a 'different' init method that
        /// doesn't block the thread of the former (soon to die) session.
        /// </remarks>
        /// <exception cref="BEEPException" />
        private TCPSession(System.Net.Sockets.TcpClient sock, ProfileRegistry registry, int firstChannel, SessionCredential localCred, SessionCredential peerCred, SessionTuningProperties tuning, string servername)
            : base(registry, firstChannel, localCred, peerCred, tuning, servername)
        {
            InitBlock();

            socket = sock;
            writerLock = new object();

            if ((peerCred != null) || (localCred != null) || (tuning != null))
            {
                tuningInit();
            }
            else
            {
                init();
            }

            try
            {
                socket.ReceiveBufferSize = MAX_RECEIVE_BUFFER_SIZE;
            }
            catch (System.Exception)
            {
                log.debug("Socket doesn't support setting receive buffer size");
            }
        }
Beispiel #6
0
        protected internal override ISession reset(SessionCredential localCred, SessionCredential peerCred, SessionTuningProperties tuning, ProfileRegistry reg, object argument)
        {
            lock(this)
            {

                if (log.isTraceEnabled())
                {
                    log.trace("Reset as " + (Initiator?"INITIATOR":"LISTENER"));
                }

                System.Net.Sockets.TcpClient s = argument as System.Net.Sockets.TcpClient;

                if(s == null)
                {
                    s = this.socket;
                }

                if (reg == null)
                {
                    reg = this.ProfileRegistry;
                }

                ISession newSession = new TCPSession(s, reg, (Initiator?CHANNEL_START_ODD:CHANNEL_START_EVEN), localCred, peerCred, tuning, null);

                this.fireSessionReset(newSession);

                return newSession;
            }
        }
Beispiel #7
0
		/// <summary>sets the tuning properties for this session</summary>
		/// <param name="tuning"></param>
		/// <seealso cref="SessionTuningProperties"></seealso>
		protected internal virtual void  setTuningProperties(SessionTuningProperties tuning)
		{
			tuningProperties = tuning;
		}
Beispiel #8
0
		/// <summary>This method is used by a tuning profile to reset the session after the
		/// tuning is complete.</summary>
		/// <returns>A new <code>Session</code> with the tuning complete.</returns>
		protected internal abstract ISession reset(SessionCredential localCred, SessionCredential peerCred, SessionTuningProperties tuning, ProfileRegistry registry, object argument);
Beispiel #9
0
		/// <summary>Default Session Constructor.  A relationship between peers - a session -
		/// consists of a set of profiles they share in common, and an ordinality
		/// (to prevent new channel collision) so that the initiator starts odd
		/// channels and the listener starts channels with even numbers.</summary>
		/// <param name="registry">The Profile Registry summarizing the profiles this
		/// Session will support</param>
		/// <param name="firstChannel">used internally in the API, an indication of the
		/// ordinality of the channels this peer can start, odd, or even.</param>
		/// <param name="localCred"></param>
		/// <param name="peerCred"></param>
		/// <param name="tuning"></param>
		/// <param name="serverName"></param>
		protected internal SessionImpl(ProfileRegistry registry, int firstChannel, SessionCredential localCred, SessionCredential peerCred, SessionTuningProperties tuning, string serverName)
		{
			log = LogFactory.getLog(this.GetType());

			state = core.SessionState.SESSION_STATE_INITIALIZED;
			localCredential = localCred;
			peerCredential = peerCred;
			nextChannelNumber = firstChannel;
			overflow = false;
			profileRegistry = registry;
			channels = new System.Collections.Hashtable(DEFAULT_CHANNELS_SIZE);
			properties = new System.Collections.Hashtable(DEFAULT_PROPERTIES_SIZE);
			tuningProperties = tuning;
			this.serverName = serverName;
		}