强制关闭用户的WebSocket

@param userid        Serializable
@param targetAddress InetSocketAddress

@return 无返回值
421282
@Override
    public CompletableFuture<Integer> forceCloseWebSocket(Serializable userid, @RpcTargetAddress InetSocketAddress targetAddress) {
        //不能从sncpNodeAddresses中移除，因为engine.forceCloseWebSocket 会调用到disconnect
        if (logger.isLoggable(Level.FINEST)) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + userid + " forceCloseWebSocket from " + targetAddress);
        if (localEngine == null) return CompletableFuture.completedFuture(0);
        return CompletableFuture.completedFuture(localEngine.forceCloseLocalWebSocket(userid));
    }
742005
@Override
    public CompletableFuture<Void> disconnect(Serializable userid, InetSocketAddress sncpAddr) {
        tryAcquireSemaphore();
        CompletableFuture<Void> future = sncpNodeAddresses.removeSetItemAsync(SOURCE_SNCP_USERID_PREFIX + userid, InetSocketAddress.class, sncpAddr);
        if (semaphore != null) future.whenComplete((r, e) -> releaseSemaphore());
        if (logger.isLoggable(Level.FINEST)) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + userid + " disconnect from " + sncpAddr);
        return future;
    }
817944
public void setTargetAddress(String targetAddress)
    {
        try
        {
            this.JOB.setDialstring(targetAddress);
        }
        catch(Exception exception)
        {
            throw new FaxException("Error while setting job target address.",exception);
        }
    }
1321149
public String addAddressToTarget(String address)
    {
        if (address != null)
        {
            MessageDetailTarget messageDetailTarget = (MessageDetailTarget)this.getMainRecord();
            String site = messageDetailTarget.getProperty(TrxMessageHeader.DESTINATION_PARAM);
            site = this.getSiteFromAddress(address, site);
            if (!messageDetailTarget.setProperty(TrxMessageHeader.DESTINATION_PARAM, site))
                address = null; // This type doesn't take properties (never)
            messageDetailTarget.setProperty(TrxMessageHeader.DESTINATION_MESSAGE_PARAM, this.getPathFromAddress(address, site));
            String wsdlPath = messageDetailTarget.getProperty(TrxMessageHeader.WSDL_PATH);
            wsdlPath = this.getPathFromAddress(wsdlPath, site);
            if (wsdlPath != null)
                messageDetailTarget.setProperty(TrxMessageHeader.WSDL_PATH, wsdlPath);
        }
        return address;
    }
181077
public void connectUsingTrmWithTargetData(String targetType, String targetSignificance, String target)
                    throws ResourceException
    {
        final String methodName = "connectUsingTrmWithTargetData";
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled())
        {
            SibTr.entry(this, TRACE, methodName, new Object[] { targetType, targetSignificance, target });
        }

        synchronized (_connections)
        {
            // At this point in the code path we can be sure that:
            // 1. There are no local preferred ME's (this method would not be called if there were)
            // 2. Target data has been set (we are in the else block of the "if (target == null)" block
            // 
            // Since we have been passed target data it means we are attempting to create a connection
            // to a preferred (or required) ME (no target data is ever passed if we are trying to create
            // a connection to a non preferred ME). With this in mind, if we are currently connected to
            // a non preferred ME (_connectToPreferred is false) or we do not currently have a connection
            // then we'll try and create a connection that matches our target data. If a connection
            // is created then we should close any non preferred connections (if they are any).
            if ((!_connectedToPreferred) || (_connections.size() == 0))
            {
                // Set to required (even if user opted for preferred)
                // Pass targetType and target from user data.
                SibRaMessagingEngineConnection newConnection = null;
                try
                {
                    newConnection = new SibRaMessagingEngineConnection(this, _endpointConfiguration.getBusName(),
                                    targetType, SibTrmConstants.TARGET_SIGNIFICANCE_REQUIRED, target);

                    dropNonPreferredConnections();

                    if (newConnection.getConnection() != null) {
                        _connections.put(newConnection.getConnection().getMeUuid(), newConnection);
                        createListener(newConnection);

                    }

                    if (_connections.size() > 0)
                    {
                        _connectedRemotely = checkIfRemote(_connections.values()
                                        .iterator().next());
                        _connectedToPreferred = true;

                        if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled())
                        {
                            SibTr.debug(TRACE, "We have connect <remote=" + _connectedRemotely + " > <preferred="
                                               + _connectedToPreferred + ">");
                        }
                    }
                } catch (final SIResourceException exception)
                {
                    // No FFDC code needed
                    // We are potentially connecting remotely so this error may be transient
                    // Possibly the remote ME is not available
                    SibTr.warning(TRACE, SibTr.Suppressor.ALL_FOR_A_WHILE, "TARGETTED_CONNECTION_FAILED_CWSIV0787",
                                  new Object[] { targetType, targetSignificance, target, _endpointConfiguration.getBusName() });
                    if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled())
                    {
                        SibTr.debug(TRACE, "Failed to obtain a connection - retry after a set interval");
                    }
                } catch (final SIException exception)
                {
                    FFDCFilter.processException(exception, CLASS_NAME + "." + methodName, "1:711:1.45", this);

                    if (TraceComponent.isAnyTracingEnabled() && TRACE.isEventEnabled())
                    {
                        SibTr.exception(this, TRACE, exception);
                    }

                    throw new ResourceException(NLS.getFormattedMessage("CONNECT_FAILED_CWSIV0782", new Object[] {
                                                                                                                  _endpointConfiguration.getDestination().getDestinationName(),
                                                                                                                  _endpointConfiguration.getBusName(), this, exception }, null), exception);
                }
            }
        } // Sync block

        // Failed to get a preferred one, try for any ME next.
        // Also if we have connected to a remote non preferred ME we may wish to try again for a local
        // non preferred ME (We know there is not a local preferred ME as we would not be in this
        // method if there were).
        if (((_connections.size() == 0) || (_connectedRemotely && !_connectedToPreferred && _destinationStrategy
                        .isDropRemoteNonPreferredForLocalNonPreferred()))
            && (targetSignificance.equals(SibTrmConstants.TARGET_SIGNIFICANCE_PREFERRED)))
        {
            if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled())
            {
                SibTr.debug(TRACE,
                            "Could not obtain the preferred connection - try again without any target preferences");
            }
            // For durable pub sub there are no local preferred MEs, for point to point and non durable pub
            // sub then they all count as preferred
            connect(_destinationStrategy.isDurablePubsSub() ? null : getMEsToCheck(), null, null, null, false);
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled())
        {
            SibTr.exit(TRACE, methodName);
        }
    }
727751
@Nullable
  public static InetSocketAddress parseInetSocketAddress(String address) throws IOException {
    if (address == null) {
      return null;
    }
    String[] strArr = address.split(":");
    if (strArr.length != 2) {
      throw new IOException("Invalid InetSocketAddress " + address);
    }
    return new InetSocketAddress(strArr[0], Integer.parseInt(strArr[1]));
  }
220270
public static InetSocketAddress toInetSocketAddress(URI uri) {
		final InetAddress adr = toInetAddress(uri);
		final int port = uri.getPort();
		if (port <= 0) {
			throw new IllegalArgumentException(uri.toString());
		}
		return new InetSocketAddress(adr, port);
	}
1025372
public WebSocket setUserInfo(String id, String password)
    {
        mHandshakeBuilder.setUserInfo(id, password);

        return this;
    }
459183
public static final void forwardJSMessage(JsMessage jsMsg,
                                            SIBUuid8 targetMEUuid, 
                                            String destName,
                                            boolean temporary)
  {
    if (jsMsg.isApiMessage())
    {
      String apiMsgId = null;
      String correlationId = null;
      
      String msg = "MESSAGE_FORWARDED_CWSJU0022";
      if (temporary)
        msg = "MESSAGE_FORWARDED_TEMP_CWSJU0122";
      
      if (jsMsg instanceof JsApiMessage)
      {
        apiMsgId = ((JsApiMessage) jsMsg).getApiMessageId();
        correlationId = ((JsApiMessage) jsMsg).getCorrelationId();
      }
      else
      {
        if (jsMsg.getApiMessageIdAsBytes() != null) 
          apiMsgId = new String(jsMsg.getApiMessageIdAsBytes());
        
        if (jsMsg.getCorrelationIdAsBytes() != null) 
          correlationId = new String(jsMsg.getCorrelationIdAsBytes());
      }
      
      //  As we are forwarding to a foreign bus then the likelyhood is that we can't obtain the
      //  name anyway so just use the uuid. Calling getMENameByUuidx has significant
      //  delays if the ME Name can't be found (1 minute plus)
      String meName = targetMEUuid.toString();
      
      if (tc_mt.isDebugEnabled())
        SibTr.debug(UserTrace.tc_mt, nls_mt.getFormattedMessage(
            msg, new Object[]
             { apiMsgId, jsMsg.getSystemMessageId(), correlationId, meName,
                destName }, null));
      }
  }
780941
protected final ChannelFuture doConnect(InetSocketAddress target)
	{
		ChannelHandler fixHandler=fixHandlerBeforeConnect(channelInitFix(handler));//修正handler
		return doBooterConnect(target, fixHandler);
	}
736515
public static TcpServerTransport create(InetSocketAddress address) {
    Objects.requireNonNull(address, "address must not be null");

    return create(address.getHostName(), address.getPort());
  }
1316050
public static SSLServerSocketChannel open(SocketAddress address) throws IOException
    {
        try
        {
            return open(address, SSLContext.getDefault());
        }
        catch (NoSuchAlgorithmException ex)
        {
            throw new IOException(ex);
        }
    }
726472
@Override
  public InetAddress addressRemote()
  {
    SocketChannel s = _channel;
    
    if (s != null) {
      try {
        InetSocketAddress addr = (InetSocketAddress) s.getRemoteAddress();
        
        return addr.getAddress();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      return null;
    }
  }
975526
@Override
    public void bind(SocketAddress bindpoint) throws IOException {
	super.bind(bindpoint);
	this.addr = (UNIXSocketAddress) bindpoint;
    }
396779
public static WebhookCreator creator(final String pathSessionSid, 
                                         final Webhook.Target target) {
        return new WebhookCreator(pathSessionSid, target);
    }
865659
public Socket connectSocket(
        final Socket sock,
        final String host,
        final int port,
        final InetAddress localAddress,
        int localPort,
        final HttpParams params
    ) throws IOException {

        if (host == null) {
            throw new IllegalArgumentException("Target host may not be null.");
        }
        if (params == null) {
            throw new IllegalArgumentException("Parameters may not be null.");
        }

        SSLSocket sslsock = (SSLSocket)
            ((sock != null) ? sock : createSocket());

        if ((localAddress != null) || (localPort > 0)) {

            // we need to bind explicitly
            if (localPort < 0)
                localPort = 0; // indicates "any"

            InetSocketAddress isa =
                new InetSocketAddress(localAddress, localPort);
            sslsock.bind(isa);
        }

        int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
        int soTimeout = HttpConnectionParams.getSoTimeout(params);

        InetSocketAddress remoteAddress;
        if (this.nameResolver != null) {
            remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port); 
        } else {
            remoteAddress = new InetSocketAddress(host, port);            
        }
        
        sslsock.connect(remoteAddress, connTimeout);

        sslsock.setSoTimeout(soTimeout);
        try {
            hostnameVerifier.verify(host, sslsock);
            // verifyHostName() didn't blowup - good!
        } catch (IOException iox) {
            // close the socket before re-throwing the exception
            try { sslsock.close(); } catch (Exception x) { /*ignore*/ }
            throw iox;
        }

        return sslsock;
    }
1215409
public Socket getSocket(String host, int port, boolean useSecureSocket) throws Exception 
	{
		// Get the registered security domain for the URI
		SecurityDomain securityDomain = null;
		if (useSecureSocket) {
			securityDomain = CONTEXT.getSecurityDomainManager().getSecurityDomain(host,port);
		}
		return getSocket(host,port,useSecureSocket,securityDomain);
	}