public void blockUntilRespond() throws InterruptedException {
   // Block thread by trying to acquire the semaphore a second time.
   boolean acquired = semaphore.tryAcquire(TIMEOUT, TimeUnit.MINUTES);
   if (acquired) {
     // Release the semaphore previously acquired.
     semaphore.release();
   } else {
     LOG.error(
         "No response sent to "
             + "request '"
             + request.getRequestURI()
             + "' "
             + "with ICEfaces ID '"
             + request.getParameter("ice.session")
             + "' "
             + "from "
             + request.getRemoteAddr()
             + " "
             + "in "
             + TIMEOUT
             + " minutes.  "
             + "Unblocking "
             + "thread '"
             + Thread.currentThread().getName()
             + "'.");
     // Release the semaphore; most probably respondWith() method was not invoked.
     semaphore.release();
   }
 }
コード例 #2
0
  private void sendViaNewChannel(
      final MessageContext context,
      final MessageContext receivingContext,
      final OutMessage message,
      final String uri)
      throws XFireException {
    try {
      Channel channel;
      PipedInputStream stream = new PipedInputStream();
      PipedOutputStream outStream = new PipedOutputStream(stream);
      try {
        channel = getTransport().createChannel(uri);
      } catch (Exception e) {
        throw new XFireException("Couldn't create channel.", e);
      }

      Semaphore s = new Semaphore(2);
      try {
        getWorkManager().scheduleWork(new WriterWorker(outStream, message, context, s));
        getWorkManager()
            .scheduleWork(new ReaderWorker(stream, message, channel, uri, receivingContext, s));
      } catch (WorkException e) {
        throw new XFireException("Couldn't schedule worker threads. " + e.getMessage(), e);
      }

      try {
        s.acquire();
      } catch (InterruptedException e) {
        // ignore is ok
      }
    } catch (IOException e) {
      throw new XFireRuntimeException("Couldn't create stream.", e);
    }
  }
 public void respondWith(final ResponseHandler handler) throws Exception {
   try {
     super.respondWith(handler);
   } finally {
     semaphore.release();
   }
 }
 public ThreadBlockingRequestResponse(HttpServletRequest request, HttpServletResponse response)
     throws Exception {
   super(request, response);
   semaphore = new Semaphore(1);
   // Acquire semaphore hoping to have it released by a call to respondWith() method.
   semaphore.acquire();
 }
コード例 #5
0
    public void run() {
      try {
        final XMLStreamWriter writer =
            STAXUtils.createXMLStreamWriter(stream, message.getEncoding(), context);
        message.getSerializer().writeMessage(message, writer, context);

        writer.close();
        stream.close();

      } catch (Exception e) {
        throw new XFireRuntimeException("Couldn't write stream.", e);
      } finally {
        semaphore.release();
      }
    }
コード例 #6
0
    public void run() {
      try {
        final XMLStreamReader reader =
            STAXUtils.createXMLStreamReader(stream, message.getEncoding(), context);
        final InMessage inMessage = new InMessage(reader, uri);
        inMessage.setEncoding(message.getEncoding());

        channel.receive(context, inMessage);

        reader.close();
        stream.close();
      } catch (Exception e) {
        throw new XFireRuntimeException("Couldn't read stream.", e);
      } finally {
        semaphore.release();
      }
    }