/*
(non-Javadoc)

@see org.jsmpp.PDUSender#sendUnbind(java.io.OutputStream, int)
2490
public byte[] sendUnbind(OutputStream os, int sequenceNumber)
            throws IOException {
        byte[] b = pduComposer.unbind(sequenceNumber);
        writeAndFlush(os, b);
        return b;
    }
799352
private void release() {
        try {
            Method release = BoundObjectTable.Table.class.getDeclaredMethod("release", String.class);
            release.setAccessible(true);
            release.invoke(boundObjectTable, boundId);
        } catch (Exception x) {
            LOG.log(Level.WARNING, "failed to unbind " + boundId, x);
        }
    }
676332
public byte[] outbind(int sequenceNumber, String systemId, String password)
            throws PDUStringException {
        StringValidator.validateString(systemId, StringParameter.SYSTEM_ID);
        StringValidator.validateString(password, StringParameter.PASSWORD);

        PDUByteBuffer buf = new PDUByteBuffer(SMPPConstant.CID_OUTBIND, 0,
                sequenceNumber);
        buf.append(systemId);
        buf.append(password);
        return buf.toBytes();
    }
952452
@Override
  public void sendRegistrationTerminationAnswer(JRegistrationTerminationAnswer answer)
      throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
    send(Event.Type.SEND_MESSAGE, null, answer);
  }
1182663
public void valueUnbound(HttpSessionBindingEvent event) {
        for (SessionFieldMapper fieldMapper : this.values()) {
            if (fieldMapper.runnable != null) fieldMapper.runnable.cancel();
        }
    }
1370025
@Handler
    public void onOutput(Output<ByteBuffer> event,
            PlainChannel plainChannel)
            throws InterruptedException, SSLException, ExecutionException {
        if (plainChannel.hub() != this) {
            return;
        }
        plainChannel.sendUpstream(event);
    }
537434
private void send(final Destination d, final Priority p, final byte[] apdu, final int response)
		throws KNXTimeoutException, KNXDisconnectException, KNXLinkClosedException
	{
		svcResponse = response;
		if (d.isConnectionOriented()) {
			tl.connect(d);
			tl.sendData(d, p, apdu);
		}
		else
			tl.sendData(d.getAddress(), p, apdu);
	}
720090
public void unbind(String name) throws ObjectNameNotFoundException
    {
        /**
         * Is DB open? ODMG 3.0 says it has to be to call unbind.
         */
        if (!this.isOpen())
        {
            throw new DatabaseClosedException("Database is not open. Must have an open DB to call unbind");
        }
        TransactionImpl tx = getTransaction();
        if (tx == null || !tx.isOpen())
        {
            throw new TransactionNotInProgressException("Tx is not open. Must have an open TX to call lookup.");
        }

        tx.getNamedRootsMap().unbind(name);
    }
226827
public void valueUnbound( HttpSessionBindingEvent event )
    {
        //
        // We may have lost our transient ServletContext reference.  Try to get the ServletContext reference from the
        // HttpSession object if necessary.
        //
        ServletContext servletContext = getServletContext();
        HttpSession session = event.getSession();

        if ( servletContext == null && session != null )
        {
            servletContext = session.getServletContext();
        }

        if ( servletContext != null )
        {
            if ( !_isDestroyed && Handlers.get( servletContext ).getStorageHandler().allowBindingEvent( event ) )
            {
                destroy( session );
                _isDestroyed = true;
            }
        }
    }
754408
public void send(final byte[] frame, final boolean waitForCon)
		throws KNXPortClosedException, KNXAckTimeoutException, InterruptedException
	{
		final boolean group = (frame[3] & 0x80) == 0x80;
		KNXAddress dst = null;
		if (group) {
			dst = new GroupAddress(new byte[] { frame[6], frame[7] });
			sending.add(dst);
		}

		try {
			final byte[] data = toUartServices(cEmiToTP1(frame));
			if (logger.isTraceEnabled())
				logger.trace("create UART services {}", DataUnitBuilder.toHex(data, " "));
			req = frame.clone();
			final long start = System.nanoTime();
			synchronized (enterIdleLock) {
				while (!idle)
					enterIdleLock.wait();
			}
			logger.trace("UART ready for sending after {} us", (System.nanoTime() - start) / 1000);

			logger.debug("write UART services, {}", (waitForCon ? "waiting for .con" : "non-blocking"));
			os.write(data);
			state = ConPending;
			if (!waitForCon)
				return;
			if (waitForCon())
				return;
			throw new KNXAckTimeoutException("no ACK for L-Data.con");
		}
		catch (final InterruptedIOException e) {
			throw new InterruptedException(e.getMessage());
		}
		catch (final IOException e) {
			close();
			throw new KNXPortClosedException("I/O error", portId, e);
		}
		finally {
			req = null;
			sending.remove(dst);
		}
	}
1287787
def unbind(self, queue, exchange, routing_key='', arguments={},
               ticket=None, cb=None):
        '''
        
        '''
        args = Writer()
        args.write_short(ticket or self.default_ticket).\
            write_shortstr(queue).\
            write_shortstr(exchange).\
            write_shortstr(routing_key).\
            write_table(arguments)
        self.send_frame(MethodFrame(self.channel_id, 50, 50, args))

        self._unbind_cb.append(cb)
        self.channel.add_synchronous_cb(self._recv_unbind_ok)
54083
@Override
    public void sendAckExpectedMessage(
                                       long ackExpStamp,
                                       int priority,
                                       Reliability reliability,
                                       SIBUuid12 stream)
                    throws SIResourceException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "sendAckExpectedMessage",
                        new Object[] { new Long(ackExpStamp), new Integer(priority), reliability, stream });
        HashMap allPubSubOutputHandlers = _destination.getAllPubSubOutputHandlers();
        try
        {
            Iterator itr = allPubSubOutputHandlers.values().iterator();

            while (itr.hasNext())
            {
                PubSubOutputHandler handler = (PubSubOutputHandler) itr.next();

                // Send AckExpected to all OutputHandlers
                handler.processAckExpected(ackExpStamp, priority, reliability, stream);
            }
        } finally
        {
            // By calling the getAllPubSubOutputHandlers it will lock the 
            // handlers
            _destination.unlockPubsubOutputHandlers();
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "sendAckExpectedMessage");
    }
1190464
public void sendStream(InputStream inStream, int remaining) throws IOException {
    int expectedLength = remaining;
    if (streamBuffer == null) {
      streamBuffer = new byte[8192];
    }

    while (remaining > 0) {
      int count = (remaining > streamBuffer.length ? streamBuffer.length : remaining);
      int readCount;

      try {
        readCount = inStream.read(streamBuffer, 0, count);
        if (readCount < 0) {
          throw new EOFException(
              GT.tr("Premature end of input stream, expected {0} bytes, but only read {1}.",
                  expectedLength, expectedLength - remaining));
        }
      } catch (IOException ioe) {
        while (remaining > 0) {
          send(streamBuffer, count);
          remaining -= count;
          count = (remaining > streamBuffer.length ? streamBuffer.length : remaining);
        }
        throw new PGBindException(ioe);
      }

      send(streamBuffer, readCount);
      remaining -= readCount;
    }
  }
769170
void sendNextProtocol(NextProtoNego.Provider provider) throws IOException
    {
        if (isInitialHandshake && provider != null)
        {
            if (protocols == null)
            {
                if (NextProtoNego.debug)
                    System.err.println(new StringBuilder("[C] NPN not received for ").append(conn != null ? conn : engine));
                ((NextProtoNego.ClientProvider)provider).unsupported();
            }
            else
            {
                try
                {
                    String protocol = ((NextProtoNego.ClientProvider)provider).selectProtocol(protocols);
                    if (NextProtoNego.debug)
                        System.err.println(new StringBuilder("[C] NPN selected '").append(protocol).append("' for ").append(conn != null ? conn : engine));
                    new NextProtocolMessage(protocol).write(output);
                    output.flush();
                }
                catch(Throwable t)
                {
                    fatalSE(Alerts.alert_handshake_failure, "NPN protocol selection failure", t);
                }
            }
        }
    }
1359406
@Override
	protected void unserializeFrom(RawDataBuffer in)
    {
        super.unserializeFrom(in);
        sessionId = new IntegerID(in.readInt());
        transacted = in.readBoolean();
        acknowledgeMode = in.readInt();
    }
181918
@FFDCIgnore({WebApplicationException.class, IOException.class, NoSuitableMessageBodyWriterException.class})
    @Override
    public CompletionStage<?> send(OutboundSseEvent event) {
        final CompletableFuture<?> future = new CompletableFuture<>();

        if (!closed) {
            if (writer != null) {
                ByteArrayOutputStream os = null;
                try {
                    os = new ByteArrayOutputStream();
                    writer.writeTo(event, event.getClass(), null, new Annotation [] {}, event.getMediaType(), null, os);

                    String eventContents = os.toString();
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "send - sending " + eventContents);
                    }

                    if (!response.isCommitted()) {
                        response.setHeader("Content-Type", MediaType.SERVER_SENT_EVENTS);
                        response.flushBuffer();
                    }

                    //TODO: this seems like a bug, but most SSE clients seem to expect a named event
                    //      so for now, we will provide one if one is not provided by the user
                    if (event.getName() == null) {
                        response.getOutputStream().print("    UnnamedEvent\n");
                    }
                    response.getOutputStream().println(eventContents);
                    response.getOutputStream().flush();

                    return CompletableFuture.completedFuture(eventContents);
                } catch (NoSuitableMessageBodyWriterException ex) {
                    handleException(ex, future, event);
                    throw new IllegalArgumentException("No suitable message body writer for OutboundSseEvent created with data " + event.getData() + " and mediaType " + event.getMediaType() + ". The data contained within the OutboundSseEvent must match the mediaType."); 
                } catch (WebApplicationException ex) {
                    handleException(ex, future, event);
                } catch (IOException ex) {
                    handleException(ex, future, event);
                } finally {
                    if (os != null) {
                        try {
                            os.close();
                        } catch (IOException ex) {
                            //ignore
                        }
                    }
                }
            } else {  //no writer
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "No MessageBodyWriter - returning null for event:  " + event);
                }
                future.complete(null);
            }  
        } else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "SseEventSink is closed - failed sending event:  " + event);
            }
            throw new IllegalStateException("SseEventSink is closed.");  
        }

        return future;
    }
1173034
private void sendDataToClient(BufferedWriter outToClient, String kafToString)
      throws IOException {
    outToClient.write(kafToString);
    outToClient.close();
  }