Session connect generate channel.

@param session
the session
@return the channel
@throws JSchException
the j sch exception
321439
public Channel sessionConnectGenerateChannel(Session session)
            throws JSchException {
    	// set timeout
        session.connect(sshMeta.getSshConnectionTimeoutMillis());
        
        ChannelExec channel = (ChannelExec) session.openChannel("exec");
        channel.setCommand(sshMeta.getCommandLine());

        // if run as super user, assuming the input stream expecting a password
        if (sshMeta.isRunAsSuperUser()) {
        	try {
                channel.setInputStream(null, true);

                OutputStream out = channel.getOutputStream();
                channel.setOutputStream(System.out, true);
                channel.setExtOutputStream(System.err, true);
                channel.setPty(true);
                channel.connect();
                
	            out.write((sshMeta.getPassword()+"\n").getBytes());
	            out.flush();
			} catch (IOException e) {
				logger.error("error in sessionConnectGenerateChannel for super user", e);
			}
        } else {
        	channel.setInputStream(null);
        	channel.connect();
        }

        return channel;

    }
22489
@Override
    public Session createSession() throws JMSException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createSession");

        Session session = null;
        try {
            session = createSession(false, Session.AUTO_ACKNOWLEDGE);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "createSession");
        }

        return session;
    }
127552
public static Session create(SessionStore sessionStore, HttpRequest<?> request) {
        Session session = sessionStore.newSession();
        request.getAttributes().put(HttpSessionFilter.SESSION_ATTRIBUTE, session);
        return session;
    }
348331
function(sessionId, socketId, cb) {
      return api.store.get().load(sessionId, function(err, session) {
        // Create a new session if we don't have this sessionId in memory
        // Note: in production you should be using Redis or another
        // persistent store so this should rarely happen
        if (!session) {
          session = strategy.create(sessionId);
          debug('created session for %s',sessionId);
        } else {
          debug('using existing session for %s',sessionId);
        }

        // Append methods to session object
        session.channel = channels(ss, session, socketId);
        session.setUserId = function(userId, cb) {
          if (!cb) {
            cb = function() {};
          }
          if (userId) {
            this.userId = userId;
            this._bindToSocket();
          } else if (this.userId) {  // if null (i.e. user has signed out)
            subscriptions.user.remove(this.userId, socketId);
            delete this.userId;
          }
          return this.save(cb);
        };

        // Bind username and any channel subscriptions to this socketID on each request
        session._bindToSocket = function() {
          if (session.userId) {
            subscriptions.user.add(session.userId, socketId);
          }
          if ((session.channels) && session.channels.length > 0) {
            session.channel._bindToSocket();
          }
          return this;
        };
        session.save = function(cb) {
          return sessionStore.set(sessionId, session, cb);
        };
        session._bindToSocket();
        return cb(session);
      });
    }
525350
function Session(channel, config, cb) {
  events.EventEmitter.call(this)

  this._agents  = new SMap()
  this._ragents = new SMap()

  var agentInfo = {
    id:    "server",
    name:  "server",
    title: "server"
  }

  this._ragentServer = agents.createRAgent(this, agentInfo)

  this._ragentServer.addListener("agentCreated",   onRAgentCreated)
  this._ragentServer.addListener("agentDestroyed", onRAgentDestroyed)

  channel.on("message", onMessage)
  channel.on("close",   onClose)
  channel.on("error",   onError)

  DEBUG("connect")

  channel.connect(onConnect)

  var session = this

  //-----------------------------------
  function onConnect(err) {
    if (err) {
      DEBUG("connect error", err)
      return cb(err)
    }

    DEBUG("connected")

    channel.sendMessage({
      type: "request",
      name: "connect",
      to:   "server",
      id:   "0",
      body: {
        key: config.key
      }
    })
  }

  //-----------------------------------
  function onMessage(message) {

    if (!session._channel) {
      DEBUG("channel connection message received")
      if (message.type != "response") return
      if (message.name != "connect") return
      if (message.from != "server") return
      if (message.id   != "0") return

      DEBUG("channel connection message accepted")

      session._channel = channel
      cb(null, session)
      return
    }

    var agent

    if (message.to == "server") {
      if (message.type == "request")     agent = session._ragentServer
    }

    else if (message.from == "server") {
      if (message.type == "response")    agent = session._ragentServer
      if (message.type == "event")       agent = session._ragentServer
    }

    else if (message.type == "request")  agent = session._agents.get(message.to)
    else if (message.type == "response") agent = session._ragents.get(message.from)
    else if (message.type == "event")    agent = session._ragents.get(message.from)

    if (!agent) return

    if      (message.type == "request")  agent._onRequest(message)
    else if (message.type == "response") agent._onResponse(message)
    else if (message.type == "event")    agent._onEvent(message)
  }

  //-----------------------------------
  function onClose() {
    DEBUG("closing")

    session._agents.forEach(function (agent) {
      agent.destroy()
    })

    session._agents  = null
    session._channel = null
    session.emit("close")

    // only 'works' if the cb has not already been called
    cb(new Error("closed"))
  }

  //-----------------------------------
  function onError(err) {
    DEBUG("error", err)
    session.emit("error", err)
  }

  //-----------------------------------
  function onRAgentCreated(agentInfo) {
    DEBUG("ragentCreated", utils.JS(agentInfo))
    var ragent = agents.createRAgent(session, agentInfo)

    session._ragents.set(agentInfo.id, ragent)
    session.emit("ragentCreated", ragent)
  }

  //-----------------------------------
  function onRAgentDestroyed(agentInfo) {
    DEBUG("ragentDestroyed", utils.JS(agentInfo))
    var ragent = session._ragents.get(agentInfo.id)
    if (!ragent) return

    session._ragents.delete(agentInfo.id)
    session.emit("ragentDestroyed", ragent)
  }

}
928804
public static Session getSession(final ICommandLine cl) throws Exception {
        JSch jsch = new JSch();
        Session session = null;
        int timeout = DEFAULT_TIMEOUT;
        int port = cl.hasOption("port") ? Integer.parseInt(cl.getOptionValue("port")) : +DEFAULT_PORT;
        String hostname = cl.getOptionValue("hostname");
        String username = cl.getOptionValue("username");
        String password = cl.getOptionValue("password");
        String key = cl.getOptionValue("key");
        if (cl.hasOption("timeout")) {
            try {
                timeout = Integer.parseInt(cl.getOptionValue("timeout"));
            } catch (NumberFormatException e) {
                throw new MetricGatheringException("Invalid numeric value for timeout.", Status.CRITICAL, e);
            }
        }
        session = jsch.getSession(username, hostname, port);
        if (key == null) {
            session.setConfig("StrictHostKeyChecking", "no");
            session.setPassword(password);
        } else {
            jsch.addIdentity(key);
        }
        session.connect(timeout * 1000);
        return session;
    }
937467
protected final NioSessionConfig buildSessionConfig(SelectableChannel sc,
      Queue<WriteMessage> queue) {
    final NioSessionConfig sessionConfig =
        new NioSessionConfig(sc, getHandler(), this.selectorManager, getCodecFactory(),
            getStatistics(), queue, this.dispatchMessageDispatcher, isHandleReadWriteConcurrently(),
            this.sessionTimeout, this.configuration.getSessionIdleTimeout());
    return sessionConfig;
  }
341826
public static void close(Session session) {
		if (session != null && session.isConnected()) {
			session.disconnect();
		}
		JschSessionPool.INSTANCE.remove(session);
	}
977321
public static Channel openChannel(Session session, ChannelType channelType) {
		final Channel channel = createChannel(session, channelType);
		try {
			channel.connect();
		} catch (JSchException e) {
			throw new JschRuntimeException(e);
		}
		return channel;
	}
1357590
function SipConnection(connection, connectCallback) {
    function isData(session) {
        return !session.audio && !session.video && !session.screen && session.data;
    }

    connection.socket = {
        send: function(data) {
            var remoteSipURI = data.remoteUserId + '@yourServer.com';
            sip.publish(remoteSipURI, data); // maybe JSON.stringify(data)
        }
    };

    // connect/subscribe to SIP here

    // ref: http://sipjs.com/demo-phone/
    // and: http://sipjs.com/demo-phone/js/ua.js
    var config = {
        userAgentString: 'SIP.js/0.7.0 BB',
        traceSip: true,
        register: false,
        displayName: '',
        uri: '', // connection.userid + '@yourServer.com'
        authorizationUser: '',
        password: '',
        wsServers: 'wss://edge.sip.onsip.com'
    };

    var sip = new SIP.UA(config);

    sip.on('invite', function(session) {
        // do the stuff!
    });

    sip.on('message', function(data) {
        data = JSON.parse(data);

        if (data.eventName === connection.socketMessageEvent) {
            onMessagesCallback(data.data);
        }

        if (data.eventName === 'presence') {
            data = data.data;
            if (data.userid === connection.userid) return;
            connection.onUserStatusChanged({
                userid: data.userid,
                status: data.isOnline === true ? 'online' : 'offline',
                extra: connection.peers[data.userid] ? connection.peers[data.userid].extra : {}
            });
        }
    });

    // connected or registered
    sip.on('connected', function() {
        if (connection.enableLogs) {
            console.info('SIP connection is opened.');
        }

        connection.socket.emit('presence', {
            userid: connection.userid,
            isOnline: true
        });

        if (connectCallback) connectCallback(connection.socket);
    });

    sip.on('unregistered', function() {
        if (!connection.enableLogs) return;
        console.warn('Socket connection is closed.');
    });

    connection.socket.emit = function(eventName, data, callback) {
        if (eventName === 'changed-uuid') return;
        if (data.message && data.message.shiftedModerationControl) return;

        connection.socket.send({
            eventName: eventName,
            data: data
        });

        if (callback) {
            callback(true);
        }
    };

    var mPeer = connection.multiPeersHandler;

    function onMessagesCallback(message) {
        if (message.remoteUserId != connection.userid) return;

        if (connection.peers[message.sender] && connection.peers[message.sender].extra != message.message.extra) {
            connection.peers[message.sender].extra = message.message.extra;
            connection.onExtraDataUpdated({
                userid: message.sender,
                extra: message.message.extra
            });
        }

        if (message.message.streamSyncNeeded && connection.peers[message.sender]) {
            var stream = connection.streamEvents[message.message.streamid];
            if (!stream || !stream.stream) {
                return;
            }

            var action = message.message.action;

            if (action === 'ended' || action === 'stream-removed') {
                connection.onstreamended(stream);
                return;
            }

            var type = message.message.type != 'both' ? message.message.type : null;
            stream.stream[action](type);
            return;
        }

        if (message.message === 'connectWithAllParticipants') {
            if (connection.broadcasters.indexOf(message.sender) === -1) {
                connection.broadcasters.push(message.sender);
            }

            mPeer.onNegotiationNeeded({
                allParticipants: connection.getAllParticipants(message.sender)
            }, message.sender);
            return;
        }

        if (message.message === 'removeFromBroadcastersList') {
            if (connection.broadcasters.indexOf(message.sender) !== -1) {
                delete connection.broadcasters[connection.broadcasters.indexOf(message.sender)];
                connection.broadcasters = removeNullEntries(connection.broadcasters);
            }
            return;
        }

        if (message.message === 'dropPeerConnection') {
            connection.deletePeer(message.sender);
            return;
        }

        if (message.message.allParticipants) {
            if (message.message.allParticipants.indexOf(message.sender) === -1) {
                message.message.allParticipants.push(message.sender);
            }

            message.message.allParticipants.forEach(function(participant) {
                mPeer[!connection.peers[participant] ? 'createNewPeer' : 'renegotiatePeer'](participant, {
                    localPeerSdpConstraints: {
                        OfferToReceiveAudio: connection.sdpConstraints.mandatory.OfferToReceiveAudio,
                        OfferToReceiveVideo: connection.sdpConstraints.mandatory.OfferToReceiveVideo
                    },
                    remotePeerSdpConstraints: {
                        OfferToReceiveAudio: connection.session.oneway ? !!connection.session.audio : connection.sdpConstraints.mandatory.OfferToReceiveAudio,
                        OfferToReceiveVideo: connection.session.oneway ? !!connection.session.video || !!connection.session.screen : connection.sdpConstraints.mandatory.OfferToReceiveVideo
                    },
                    isOneWay: !!connection.session.oneway || connection.direction === 'one-way',
                    isDataOnly: isData(connection.session)
                });
            });
            return;
        }

        if (message.message.newParticipant) {
            if (message.message.newParticipant == connection.userid) return;
            if (!!connection.peers[message.message.newParticipant]) return;

            mPeer.createNewPeer(message.message.newParticipant, message.message.userPreferences || {
                localPeerSdpConstraints: {
                    OfferToReceiveAudio: connection.sdpConstraints.mandatory.OfferToReceiveAudio,
                    OfferToReceiveVideo: connection.sdpConstraints.mandatory.OfferToReceiveVideo
                },
                remotePeerSdpConstraints: {
                    OfferToReceiveAudio: connection.session.oneway ? !!connection.session.audio : connection.sdpConstraints.mandatory.OfferToReceiveAudio,
                    OfferToReceiveVideo: connection.session.oneway ? !!connection.session.video || !!connection.session.screen : connection.sdpConstraints.mandatory.OfferToReceiveVideo
                },
                isOneWay: !!connection.session.oneway || connection.direction === 'one-way',
                isDataOnly: isData(connection.session)
            });
            return;
        }

        if (message.message.readyForOffer || message.message.addMeAsBroadcaster) {
            connection.addNewBroadcaster(message.sender);
        }

        if (message.message.newParticipationRequest && message.sender !== connection.userid) {
            if (connection.peers[message.sender]) {
                connection.deletePeer(message.sender);
            }

            var userPreferences = {
                extra: message.message.extra || {},
                localPeerSdpConstraints: message.message.remotePeerSdpConstraints || {
                    OfferToReceiveAudio: connection.sdpConstraints.mandatory.OfferToReceiveAudio,
                    OfferToReceiveVideo: connection.sdpConstraints.mandatory.OfferToReceiveVideo
                },
                remotePeerSdpConstraints: message.message.localPeerSdpConstraints || {
                    OfferToReceiveAudio: connection.session.oneway ? !!connection.session.audio : connection.sdpConstraints.mandatory.OfferToReceiveAudio,
                    OfferToReceiveVideo: connection.session.oneway ? !!connection.session.video || !!connection.session.screen : connection.sdpConstraints.mandatory.OfferToReceiveVideo
                },
                isOneWay: typeof message.message.isOneWay !== 'undefined' ? message.message.isOneWay : !!connection.session.oneway || connection.direction === 'one-way',
                isDataOnly: typeof message.message.isDataOnly !== 'undefined' ? message.message.isDataOnly : isData(connection.session),
                dontGetRemoteStream: typeof message.message.isOneWay !== 'undefined' ? message.message.isOneWay : !!connection.session.oneway || connection.direction === 'one-way',
                dontAttachLocalStream: !!message.message.dontGetRemoteStream,
                connectionDescription: message,
                successCallback: function() {
                    // if its oneway----- todo: THIS SEEMS NOT IMPORTANT.
                    if (typeof message.message.isOneWay !== 'undefined' ? message.message.isOneWay : !!connection.session.oneway || connection.direction === 'one-way') {
                        connection.addNewBroadcaster(message.sender, userPreferences);
                    }

                    if (!!connection.session.oneway || connection.direction === 'one-way' || isData(connection.session)) {
                        connection.addNewBroadcaster(message.sender, userPreferences);
                    }
                }
            };

            connection.onNewParticipant(message.sender, userPreferences);
            return;
        }

        if (message.message.shiftedModerationControl) {
            connection.onShiftedModerationControl(message.sender, message.message.broadcasters);
            return;
        }

        if (message.message.changedUUID) {
            if (connection.peers[message.message.oldUUID]) {
                connection.peers[message.message.newUUID] = connection.peers[message.message.oldUUID];
                delete connection.peers[message.message.oldUUID];
            }
        }

        if (message.message.userLeft) {
            mPeer.onUserLeft(message.sender);

            if (!!message.message.autoCloseEntireSession) {
                connection.leave();
            }

            return;
        }

        mPeer.addNegotiatedMessage(message.message, message.sender);
    }

    window.addEventListener('beforeunload', function() {
        connection.socket.emit('presence', {
            userid: connection.userid,
            isOnline: false
        });
    }, false);
}
1048979
public void addHttpSession(final HttpSession session) {
		if (View.isInitialised() && !EventQueue.isDispatchThread()) {
			EventQueue.invokeLater(new Runnable() {

				@Override
				public void run() {
					addHttpSession(session);
				}
			});

			return;
		}

		if (sessions.contains(session))
			return;
		sessions.add(session);
		final int affectedRow = sessions.size() - 1;
		fireTableRowsInserted(affectedRow, affectedRow);
	}
473809
@OnOpen
    public void onOpen(Session session)
    {
        logger.info("WebSocket connected. : SessionId={}", session.getId());
        AmLogServerAdapter.getInstance().onOpen(session);
    }
976425
public String generateSessionId()
    {

        byte random[] = new byte[16];

        // Render the result as a String of hexadecimal digits
        StringBuilder buffer = new StringBuilder();

        int resultLenBytes = 0;

        while (resultLenBytes < sessionIdLength)
        {
            getRandomBytes(random);
            for (int j = 0;
                    j < random.length && resultLenBytes < sessionIdLength;
                    j++)
            {
                byte b1 = (byte) ((random[j] & 0xf0) >> 4);
                byte b2 = (byte) (random[j] & 0x0f);
                if (b1 < 10)
                {
                    buffer.append((char) ('0' + b1));
                }
                else
                {
                    buffer.append((char) ('A' + (b1 - 10)));
                }
                if (b2 < 10)
                {
                    buffer.append((char) ('0' + b2));
                }
                else
                {
                    buffer.append((char) ('A' + (b2 - 10)));
                }
                resultLenBytes++;
            }
        }

        if (jvmRoute != null && jvmRoute.length() > 0)
        {
            buffer.append('.').append(jvmRoute);
        }

        return buffer.toString();
    }
1224568
public long connectRenegotiate() {
        Lock readerLock = context.ctxLock.readLock();
        readerLock.lock();
        try {
            return SSLContext.sessionConnectRenegotiate(context.ctx);
        } finally {
            readerLock.unlock();
        }
    }
1330933
function Session_delChannel(channel) {
  var index = this.channels.indexOf(channel)
  if (-1 == index) return

  this.channels.splice(index, 1)
}
479398
private ServiceRefAmp sessionImpl(String address)
  {
    if (! address.startsWith("session:") || ! address.endsWith("/")) {
      throw new IllegalArgumentException(address);
    }

    String sessionId = cookie("JSESSIONID");

    if (sessionId == null) {
      sessionId = generateSessionId();

      cookie("JSESSIONID", sessionId);
    }

    return services().service(address + sessionId);
  }
1308846
public static Session newSession(String type, String path, String user,
                                     String password, HsqlProperties props,
                                     int timeZoneSeconds) {

        Database db = getDatabase(type, path, props);

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

        return db.connect(user, password, timeZoneSeconds);
    }