/*
(non-Javadoc)

@see com.ibm.ws.sib.processor.impl.interfaces.DestinationHandler#createPubSubOutputHandler(com.ibm.ws.sib.processor.proxyhandler.Neighbour)
779219
@Override
    public synchronized PubSubOutputHandler createPubSubOutputHandler(Neighbour neighbour)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "createPubSubOutputHandler", new Object[] { neighbour });

        PubSubOutputHandler handler =
                        _pubSubRealization.createPubSubOutputHandler(neighbour);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "createPubSubOutputHandler", handler);

        return handler;
    }
396872
@Override
  public <T> EventHandler<T> getHandler(
      final RemoteIdentifier destinationIdentifier, final Class<? extends T> messageType) {

    if (LOG.isLoggable(Level.FINE)) {
      LOG.log(Level.FINE, "RemoteManager: {0} destinationIdentifier: {1} messageType: {2}",
          new Object[] {this.name, destinationIdentifier, messageType.getCanonicalName()});
    }

    return new ProxyEventHandler<>(this.myIdentifier, destinationIdentifier,
        "default", this.reSendStage.<T>getHandler(), this.seqGen);
  }
467965
public static OutputSupplier<? extends OutputStream> newOutputSupplier(final Location location) {
    return new OutputSupplier<OutputStream>() {
      @Override
      public OutputStream getOutput() throws IOException {
        return location.getOutputStream();
      }
    };
  }
11869
public static ServletContextHandler create(Map<String, WebSocketHandlerWrapper> webSocketHandlers,
                                               Optional<Integer> webSocketIdleTimeoutMillis) {
        ServletContextHandler webSocketServletContextHandler = null;
        if (webSocketHandlers != null) {
            try {
                webSocketServletContextHandler = new ServletContextHandler(null, "/", true, false);
                WebSocketUpgradeFilter webSocketUpgradeFilter = WebSocketUpgradeFilter.configureContext(webSocketServletContextHandler);
                if (webSocketIdleTimeoutMillis.isPresent()) {
                    webSocketUpgradeFilter.getFactory().getPolicy().setIdleTimeout(webSocketIdleTimeoutMillis.get());
                }
                // Since we are configuring WebSockets before the ServletContextHandler and WebSocketUpgradeFilter is
                // even initialized / started, then we have to pre-populate the configuration that will eventually
                // be used by Jetty's WebSocketUpgradeFilter.
                NativeWebSocketConfiguration webSocketConfiguration = (NativeWebSocketConfiguration) webSocketServletContextHandler
                    .getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
                for (String path : webSocketHandlers.keySet()) {
                    WebSocketCreator webSocketCreator = WebSocketCreatorFactory.create(webSocketHandlers.get(path));
                    webSocketConfiguration.addMapping(new ServletPathSpec(path), webSocketCreator);
                }
            } catch (Exception ex) {
                logger.error("creation of websocket context handler failed.", ex);
                webSocketServletContextHandler = null;
            }
        }
        return webSocketServletContextHandler;
    }
1055605
public synchronized void deletePubSubOutputHandler(SIBUuid8 neighbourUUID)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "deletePubSubOutputHandler", neighbourUUID);

        // If we're being deleted then the output handlers are removed
        // through a different path, otherwise we may make a stream
        // unflushable by removing the only link to the downstream node
        // capable of flushing the stream.
        if (_baseDestinationHandler.isToBeDeleted())
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "deletePubSubOutputHandler");
            return;
        }

        _pubsubOutputHandlerLockManager.lockExclusive();
        // Remove the PubSubOutputHandler from the list of output handlers available.
        _pubsubOutputHandlers.remove(neighbourUUID);
        _pubsubOutputHandlerLockManager.unlockExclusive();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "deletePubSubOutputHandler");
    }
1238030
public ChannelFuture requestSubpartition(
			final ResultPartitionID partitionId,
			final int subpartitionIndex,
			final RemoteInputChannel inputChannel,
			int delayMs) throws IOException {

		checkNotClosed();

		LOG.debug("Requesting subpartition {} of partition {} with {} ms delay.",
				subpartitionIndex, partitionId, delayMs);

		clientHandler.addInputChannel(inputChannel);

		final PartitionRequest request = new PartitionRequest(
				partitionId, subpartitionIndex, inputChannel.getInputChannelId(), inputChannel.getInitialCredit());

		final ChannelFutureListener listener = new ChannelFutureListener() {
			@Override
			public void operationComplete(ChannelFuture future) throws Exception {
				if (!future.isSuccess()) {
					clientHandler.removeInputChannel(inputChannel);
					SocketAddress remoteAddr = future.channel().remoteAddress();
					inputChannel.onError(
							new LocalTransportException(
								String.format("Sending the partition request to '%s' failed.", remoteAddr),
								future.channel().localAddress(), future.cause()
							));
				}
			}
		};

		if (delayMs == 0) {
			ChannelFuture f = tcpChannel.writeAndFlush(request);
			f.addListener(listener);
			return f;
		} else {
			final ChannelFuture[] f = new ChannelFuture[1];
			tcpChannel.eventLoop().schedule(new Runnable() {
				@Override
				public void run() {
					f[0] = tcpChannel.writeAndFlush(request);
					f[0].addListener(listener);
				}
			}, delayMs, TimeUnit.MILLISECONDS);

			return f[0];
		}
	}
698338
public HashMap<SIBUuid8, PubSubOutputHandler> cloneAllPubSubOutputHandlers()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "cloneAllPubSubOutputHandlers");

        HashMap<SIBUuid8, PubSubOutputHandler> clone = null;
        try
        {
            _pubsubOutputHandlerLockManager.lock();
            clone = (HashMap<SIBUuid8, PubSubOutputHandler>) _pubsubOutputHandlers.clone();
        } finally
        {
            _pubsubOutputHandlerLockManager.unlock();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "cloneAllPubSubOutputHandlers", clone);
        return clone;
    }
322162
public HashMap<SIBUuid8, PubSubOutputHandler> getAllPubSubOutputHandlers()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "getAllPubSubOutputHandlers");

        _pubsubOutputHandlerLockManager.lock();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "getAllPubSubOutputHandlers", _pubsubOutputHandlers);

        return _pubsubOutputHandlers;
    }
1167425
@Override
    public void createConnector(ArbitrationResult result) {
        connector = connectorFactory.create(proxyParticipantId, result, qosSettings, statelessAsyncParticipantId);
        connectorStatusLock.lock();
        try {
            connectorStatus = ConnectorStatus.ConnectorSuccesful;
            connectorSuccessfullyFinished.signalAll();

            if (connector != null) {
                sendQueuedInvocations();
                sendQueuedSubscriptionInvocations();
                sendQueuedUnsubscribeInvocations();
                sendQueuedStatelessAsyncInvocations();
            }
        } finally {
            connectorStatusLock.unlock();
        }
    }
904104
NatsSubscription createSubscription(String subject, String queueName, NatsDispatcher dispatcher) {
        if (isClosed()) {
            throw new IllegalStateException("Connection is Closed");
        } else if (isDraining() && (dispatcher == null || dispatcher != this.inboxDispatcher.get())) {
            throw new IllegalStateException("Connection is Draining");
        }

        NatsSubscription sub = null;
        long sidL = nextSid.getAndIncrement();
        String sid = String.valueOf(sidL);

        sub = new NatsSubscription(sid, subject, queueName, this, dispatcher);
        subscribers.put(sid, sub);

        sendSubscriptionMessage(sid, subject, queueName, false);
        return sub;
    }
927264
@Override
    public void createControlAdapter()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createControlAdapter");

        DestinationHandler dh = null;
        try
        {
            ItemStream is = getItemStream();
            if (is instanceof PubSubMessageItemStream)
            {
                dh = ((PubSubMessageItemStream) is).getDestinationHandler();
                controlAdapter = new QueuedMessage(this, dh, is);
            }
            else if (is instanceof MQLinkMessageItemStream)
            {
                dh = ((MQLinkMessageItemStream) is).getDestinationHandler();
                controlAdapter = new MQLinkQueuedMessage(this, dh, is);
            }
            else if (is instanceof PtoPMessageItemStream)
            {
                dh = ((PtoPMessageItemStream) is).getDestinationHandler();
                controlAdapter = new QueuedMessage(this, dh, is);
            }
            else
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.debug(this, tc, "Unknown item stream type " + is);
            }
        } catch (Exception e)
        {
            FFDCFilter.processException(
                                        e,
                                        "com.ibm.ws.sib.processor.impl.store.items.MessageItem.createControlAdapter",
                                        "1:2585:1.244.1.40",
                                        this);

            SibTr.exception(tc, e);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "createControlAdapter");
    }
948291
@Override
    public OutputHandler choosePtoPOutputHandler(SIBUuid8 fixedMEUuid,
                                                 SIBUuid8 preferredMEUuid,
                                                 boolean localMessage,
                                                 boolean forcePut,
                                                 HashSet<SIBUuid8> scopedMEs)
                    throws
                    SIRollbackException,
                    SIConnectionLostException,
                    SIResourceException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(
                        tc,
                        "choosePtoPOutputHandler",
                        new Object[] { fixedMEUuid,
                                      preferredMEUuid,
                                      Boolean.valueOf(localMessage),
                                      Boolean.valueOf(forcePut),
                                      scopedMEs });

        OutputHandler result =
                        _protoRealization.
                                        choosePtoPOutputHandler(fixedMEUuid,
                                                                preferredMEUuid,
                                                                localMessage,
                                                                forcePut,
                                                                _singleServer, // Are we running in a single server environment?
                                                                scopedMEs);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "choosePtoPOutputHandler", result);

        return result;
    }
536494
public final ProxyHandler newProxyHandler() {
		InetSocketAddress proxyAddr = this.address.get();
		String username = this.username;
		String password = Objects.nonNull(username) && Objects.nonNull(this.password) ?
				this.password.apply(username) : null;

		switch (this.type) {
			case HTTP:
				return Objects.nonNull(username) && Objects.nonNull(password) ?
						new HttpProxyHandler(proxyAddr, username, password, this.httpHeaders.get()) :
						new HttpProxyHandler(proxyAddr, this.httpHeaders.get());
			case SOCKS4:
				return Objects.nonNull(username) ? new Socks4ProxyHandler(proxyAddr, username) :
						new Socks4ProxyHandler(proxyAddr);
			case SOCKS5:
				return Objects.nonNull(username) && Objects.nonNull(password) ?
						new Socks5ProxyHandler(proxyAddr, username, password) :
						new Socks5ProxyHandler(proxyAddr);
		}
		throw new IllegalArgumentException("Proxy type unsupported : " + this.type);
	}
599258
@Override
	public NIOClientSocketHandler createClientHandler(NIOTcpMultiplexer multiplexer, SocketChannel socketChannel)
	{
		try
		{
		    String clientId = UUIDProvider.getInstance().getShortUUID();
			NIOTcpPacketTransport transport = new NIOTcpPacketTransport(clientId,multiplexer,socketChannel,settings);
			ClientProcessor clientProcessor = new ClientProcessor(clientId,this,localEngine,transport);
			registerClient(clientProcessor);
			clientProcessor.start();
			
			return transport;
		}
		catch (PacketTransportException e)
		{
			log.error("Cannot create client processor",e);
			return null;
		}
	}
857034
public void removePubSubOutputHandlerMatchTarget(
    ControllableProxySubscription sub)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "removePubSubOutputHandlerMatchTarget", sub);

    // Remove the PubSub OutputHandler from the matchspace
    try
    {
      removeTarget(sub);
    }
    catch (MatchingException e)
    {
      FFDCFilter.processException(
        e,
        "com.ibm.ws.sib.processor.matching.MessageProcessorMatching.removePubSubOutputHandlerMatchTarget",
        "1:1363:1.117.1.11",
        this);

      SibTr.exception(tc, e);
      SibTr.error(tc, "INTERNAL_MESSAGING_ERROR_CWSIP0002",
        new Object[] {
          "com.ibm.ws.sib.processor.matching.MessageProcessorMatching",
          "1:1370:1.117.1.11",
          e });

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        SibTr.exit(tc, "removePubSubOutputHandlerMatchTarget", "SICoreException");

      throw new SIErrorException(
        nls.getFormattedMessage(
          "INTERNAL_MESSAGING_ERROR_CWSIP0002",
          new Object[] {
            "com.ibm.ws.sib.processor.matching.MessageProcessorMatching",
            "1:1381:1.117.1.11",
            e },
          null),
        e);
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "removePubSubOutputHandlerMatchTarget");
  }
710652
protected void addPubSubOutputHandler(PubSubOutputHandler handler)
  {
    if (iPubSubOutputHandlers == null)
      iPubSubOutputHandlers = new HashSet();

    // Add the PubSubOutputHandler to the list that this neighbour
    // knows about.  This is so a recovered neighbour can add the list of
    // output handlers back into the matchspace.
    iPubSubOutputHandlers.add(handler);
  }
584562
private TransportChannelHandler createChannelHandler(Channel channel, RpcHandler rpcHandler) {
    TransportResponseHandler responseHandler = new TransportResponseHandler(channel);
    TransportClient client = new TransportClient(channel, responseHandler);
    TransportRequestHandler requestHandler = new TransportRequestHandler(channel, client,
      rpcHandler, conf.maxChunksBeingTransferred());
    return new TransportChannelHandler(client, responseHandler, requestHandler,
      conf.connectionTimeoutMs(), closeIdleConnections, this);
  }