打开Channel连接

@param session Session会话
@param channelType 通道类型，可以是shell或sftp等，见{@link ChannelType}
@return {@link Channel}
@since 4.5.2
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;
	}
1332857
public static Type toHibernateType(Class<?> javaType){
		if (javaType == byte.class || javaType == Byte.class) {
			return  ByteType.INSTANCE;
		} 
		if (javaType == char.class || javaType == Character.class) {
			return   CharacterType.INSTANCE;
		} 
		if (javaType == short.class || javaType == Short.class) {
			return  ShortType.INSTANCE;
		} 
		if (javaType == int.class || javaType == Integer.class) {
			return  IntegerType.INSTANCE;
		}
		if (javaType == long.class || javaType == Long.class) {
			return  LongType.INSTANCE;
		}
		if (javaType == float.class || javaType == Float.class) {
			return  FloatType.INSTANCE;
		} 
		if (javaType == double.class || javaType == Double.class) {
			return  DoubleType.INSTANCE;
		}
		if (javaType == String.class) {
			return  StringType.INSTANCE;
		} 
		if (javaType == Date.class) {
			return  DateType.INSTANCE;
		} 
		if (javaType == Timestamp.class) {
			return  TimestampType.INSTANCE;
		}
		throw new IllegalArgumentException("does not support type: " + javaType);
	}
1065327
public static function sessionEntityTypeName($project, $session, $entityType)
    {
        return self::getSessionEntityTypeNameTemplate()->render([
            'project' => $project,
            'session' => $session,
            'entity_type' => $entityType,
        ]);
    }
260218
public static ClientTransport getReverseClientTransport(String container, AbstractChannel channel) {
        if (REVERSE_CLIENT_TRANSPORT_MAP == null) { // 初始化
            synchronized (ClientTransportFactory.class) {
                if (REVERSE_CLIENT_TRANSPORT_MAP == null) {
                    REVERSE_CLIENT_TRANSPORT_MAP = new ConcurrentHashMap<String, ClientTransport>();
                }
            }
        }
        String key = NetUtils.channelToString(channel.remoteAddress(), channel.localAddress());
        ClientTransport transport = REVERSE_CLIENT_TRANSPORT_MAP.get(key);
        if (transport == null) {
            synchronized (ClientTransportFactory.class) {
                transport = REVERSE_CLIENT_TRANSPORT_MAP.get(key);
                if (transport == null) {
                    ClientTransportConfig config = new ClientTransportConfig()
                        .setProviderInfo(new ProviderInfo().setHost(channel.remoteAddress().getHostName())
                            .setPort(channel.remoteAddress().getPort()))
                        .setContainer(container);
                    transport = ExtensionLoaderFactory.getExtensionLoader(ClientTransport.class)
                        .getExtension(config.getContainer(),
                            new Class[] { ClientTransportConfig.class },
                            new Object[] { config });
                    transport.setChannel(channel);
                    REVERSE_CLIENT_TRANSPORT_MAP.put(key, transport); // 保存唯一长连接
                }
            }
        }
        return transport;
    }
218930
void changeChannelType(final ChannelType newChannelType) throws GraphConversionException {

		if (!this.channelType.equals(newChannelType) && this.userDefinedChannelType) {
			throw new GraphConversionException("Cannot overwrite user defined channel type");
		}

		this.channelType = newChannelType;
	}
628884
def hasChannelType(self, chan):
        
        if self._chantypes is None:
            self._initChannelTypesList()
        return chan in self._chantypes
1147558
@SuppressWarnings("AmbiguousMethodReference")
  public static FunctionType toMaybeFunctionType(JSType type) {
    return type == null ? null : type.toMaybeFunctionType();
  }
1360351
protected void channelRequest(String requesttype, boolean wantreply,
			byte[] requestdata) throws SshException {

		try {
			if (requesttype.equals("exit-status")) {
				if (requestdata != null) {
					exitcode = (int) ByteArrayReader.readInt(requestdata, 0);
				}
			}

			if (requesttype.equals("exit-signal")) {

				if (requestdata != null) {
					ByteArrayReader bar = new ByteArrayReader(requestdata, 0,
							requestdata.length);
					try {
						exitsignalinfo = "Signal=" + bar.readString()
								+ " CoreDump="
								+ String.valueOf(bar.read() != 0) + " Message="
								+ bar.readString();
					} finally {
						try {
							bar.close();
						} catch (IOException e) {
						}
					}
				}

			}

			if (requesttype.equals("xon-xoff")) {
				flowControlEnabled = (requestdata != null && requestdata[0] != 0);
			}

			super.channelRequest(requesttype, wantreply, requestdata);
		} catch (IOException ex) {
			throw new SshException(ex, SshException.INTERNAL_ERROR);
		}
	}
954782
public ChannelSftp getSftpChannel() throws SftpException {

    try {
      ChannelSftp channelSftp = (ChannelSftp) this.session.openChannel("sftp");
      channelSftp.connect();
      return channelSftp;
    } catch (JSchException e) {
      throw new SftpException(0, "Cannot open a channel to SFTP server", e);
    }
  }
893265
@SuppressWarnings({ "unchecked", "PMD.ShortVariable",
        "PMD.AvoidDuplicateLiterals" })
    public <C> C[] channels(Class<C> type) {
        return Arrays.stream(channels)
            .filter(c -> type.isAssignableFrom(c.getClass())).toArray(
                size -> (C[]) Array.newInstance(type, size));
    }
441558
@Process(actionType = CreateConnection.class)
    public void createConnection(final CreateConnection action, final Dispatcher.Channel channel) {
        create(action.getAddressTemplate(), action.getInstanceName(), action.getNewModel(),
                getModelsFor(action.getAddressTemplate()), channel);
    }
829540
public ResponseOnSingeRequest executeAndGenResponse(ChannelExec channel) {
        ResponseOnSingeRequest sshResponse = new ResponseOnSingeRequest();

        InputStream in = null;
        OutputStream outputStreamStdErr = new ByteArrayOutputStream();
        StringBuilder sbStdOut = new StringBuilder();
        try {

            in = channel.getInputStream();
            channel.setErrStream(outputStreamStdErr);

            byte[] tmp = new byte[ParallecGlobalConfig.sshBufferSize];
            while (true) {
                while (in.available() > 0) {
                    int i = in.read(tmp, 0, ParallecGlobalConfig.sshBufferSize);
                    if (i < 0)
                        break;
                    sbStdOut.append(new String(tmp, 0, i));

                }

                if (channel.isClosed()) {
                    if (in.available() > 0)
                        continue;
                    sshResponse.setFailObtainResponse(false);

                    // exit 0 is good
                    int exitStatus = channel.getExitStatus();
                    sshResponse.setStatusCodeInt(exitStatus);
                    sshResponse.setStatusCode(Integer.toString(exitStatus));
                    break;
                }

                Thread.sleep(ParallecGlobalConfig.sshSleepMIllisBtwReadBuffer);
            }

            sshResponse.setResponseBody(sbStdOut.toString());
            sshResponse.setErrorMessage(outputStreamStdErr.toString());
            sshResponse.setReceiveTimeNow();
        } catch (Exception t) {
            throw new RuntimeException(t);
        }

        return sshResponse;
    }
163980
@RequestMapping(value = "/portletList", method = RequestMethod.GET)
    public ModelAndView listChannels(
            WebRequest webRequest,
            HttpServletRequest request,
            @RequestParam(value = "type", required = false) String type) {

        if (TYPE_MANAGE.equals(type)) {
            throw new UnsupportedOperationException(
                    "Moved to PortletRESTController under /api/portlets.json");
        }

        final IPerson user = personManager.getPerson(request);
        final Map<String, SortedSet<?>> registry = getRegistryOriginal(webRequest, user);

        // Since type=manage was deprecated channels is always empty but retained for backwards
        // compatibility
        registry.put("channels", new TreeSet<ChannelBean>());

        return new ModelAndView("jsonView", "registry", registry);
    }
491855
def delete_session_entity_type(project_id, session_id,
                               entity_type_display_name):
    """"""
    import dialogflow_v2 as dialogflow
    session_entity_types_client = dialogflow.SessionEntityTypesClient()

    session_entity_type_name = (
        session_entity_types_client.session_entity_type_path(
            project_id, session_id, entity_type_display_name))

    session_entity_types_client.delete_session_entity_type(
        session_entity_type_name)
501465
private static Class<? extends ServerChannel> epollServerChannelType() {
    try {
      Class<? extends ServerChannel> serverSocketChannel =
          Class
              .forName("io.netty.channel.epoll.EpollServerSocketChannel")
              .asSubclass(ServerChannel.class);
      return serverSocketChannel;
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Cannot load EpollServerSocketChannel", e);
    }
  }
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)
  }

}
581576
public MailSessionType<WebAppType<T>> getOrCreateMailSession()
   {
      List<Node> nodeList = childNode.get("mail-session");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new MailSessionTypeImpl<WebAppType<T>>(this, "mail-session", childNode, nodeList.get(0));
      }
      return createMailSession();
   }