Exemplo n.º 1
0
		/// <summary>A reentrant version of init() that doesn't block the
		/// first I/O thread waiting on a greeting when it should die
		/// and go away.</summary>
		/// <exception cref="BEEPException" />
		protected internal virtual void  tuningInit()
		{
			log.debug("Session.tuningInit");
			
			this.peerSupportedProfiles = null;
			
			GreetingListener greetingListener = new GreetingListener(this);
			
#if MESSAGELISTENER
			zero = ChannelImpl.createChannelZero(this, greetingListener, new ChannelImpl.MessageListenerAdapter(new ChannelZeroListener(this)));
#else
			zero = ChannelImpl.createChannelZero(this, greetingListener, new ChannelZeroListener(this));
#endif
			channels[CHANNEL_ZERO] = zero;
			
			// send greeting
			sendGreeting();
			changeState(core.SessionState.SESSION_STATE_GREETING_SENT);
			
			// start our listening thread we can now receive a greeting
			this.enableIO();
		}
Exemplo n.º 2
0
		/// <summary>Initializes the <code>Session</code>.  Initializes Channel Zero and its
		/// listener. Sends a greeting and waits for corresponding greeting.</summary>
		/// <exception cref="BEEPException" />
		protected internal virtual void  init()
		{
			this.peerSupportedProfiles = null;
			
			GreetingListener greetingListener = new GreetingListener(this);
			
#if MESSAGELISTENER
			zero = ChannelImpl.createChannelZero(this, greetingListener, new ChannelImpl.MessageListenerAdapter(new ChannelZeroListener(this)));
#else
			zero = ChannelImpl.createChannelZero(this, greetingListener, new ChannelZeroListener(this));
#endif
			
			channels[CHANNEL_ZERO] = zero;
			
			// send greeting
			sendGreeting();
			changeState(core.SessionState.SESSION_STATE_GREETING_SENT);
			
			// start our listening thread we can now receive a greeting
			this.enableIO();
			
			// blocks until greeting is received or MAX_GREETING_WAIT is reached
			int waitCount = 0;
			
			while ((state < core.SessionState.SESSION_STATE_ACTIVE) && (waitCount < MAX_START_CHANNEL_WAIT))
			{
				try
				{
					lock (greetingListener)
					{
						
						//zero.wait(MAX_START_CHANNEL_INTERVAL);
						System.Threading.Monitor.Wait(greetingListener, TimeSpan.FromMilliseconds(MAX_START_CHANNEL_INTERVAL));
						
						waitCount += MAX_START_CHANNEL_INTERVAL;
					}
				}
				catch (System.Threading.ThreadInterruptedException)
				{
					waitCount += MAX_START_CHANNEL_INTERVAL;
				}
			}
			
			// check the channel state and return the appropriate exception
			if (state != core.SessionState.SESSION_STATE_ACTIVE)
			{
				throw new BEEPException("Greeting exchange failed");
			}
		}