Beispiel #1
0
 public void connectionFailed(HornetQException e, boolean failedOver) {
   if (failedOver) {
     logger.info("reconnected to yamcs: {}", e.getMessage());
     for (ConnectionListener cl : connectionListeners) {
       cl.connected(connParams.getUrl());
     }
   } else {
     logger.warn("connection to yamcs failed: {}", e.getMessage());
     for (ConnectionListener cl : connectionListeners) {
       cl.connectionFailed(connParams.getUrl(), new YamcsException(e.getMessage(), e));
       cl.log(e.getMessage());
     }
   }
 }
  public Map<String, Object>[] listMessages(final String filterStr) throws Exception {
    checkStarted();

    clearIO();
    try {
      Filter filter = FilterImpl.createFilter(filterStr);
      List<Map<String, Object>> messages = new ArrayList<Map<String, Object>>();
      queue.flushExecutor();
      LinkedListIterator<MessageReference> iterator = queue.iterator();
      try {
        while (iterator.hasNext()) {
          MessageReference ref = iterator.next();
          if (filter == null || filter.match(ref.getMessage())) {
            Message message = ref.getMessage();
            messages.add(message.toMap());
          }
        }
        return messages.toArray(new Map[messages.size()]);
      } finally {
        iterator.close();
      }
    } catch (HornetQException e) {
      throw new IllegalStateException(e.getMessage());
    } finally {
      blockOnIO();
    }
  }
  public void write(
      final long position,
      final long size,
      final ByteBuffer directByteBuffer,
      final AIOCallback aioCallback) {
    if (aioCallback == null) {
      throw new NullPointerException("Null Callback");
    }

    checkOpened();
    if (poller == null) {
      startPoller();
    }

    pendingWrites.countUp();

    if (writeExecutor != null) {
      maxIOSemaphore.acquireUninterruptibly();

      writeExecutor.execute(
          new Runnable() {
            public void run() {
              long sequence = nextWritingSequence.getAndIncrement();

              try {
                write(handler, sequence, position, size, directByteBuffer, aioCallback);
              } catch (HornetQException e) {
                callbackError(
                    aioCallback, sequence, directByteBuffer, e.getType().getCode(), e.getMessage());
              } catch (RuntimeException e) {
                callbackError(
                    aioCallback,
                    sequence,
                    directByteBuffer,
                    HornetQExceptionType.INTERNAL_ERROR.getCode(),
                    e.getMessage());
              }
            }
          });
    } else {
      maxIOSemaphore.acquireUninterruptibly();

      long sequence = nextWritingSequence.getAndIncrement();

      try {
        write(handler, sequence, position, size, directByteBuffer, aioCallback);
      } catch (HornetQException e) {
        callbackError(
            aioCallback, sequence, directByteBuffer, e.getType().getCode(), e.getMessage());
      } catch (RuntimeException e) {
        callbackError(
            aioCallback,
            sequence,
            directByteBuffer,
            HornetQExceptionType.INTERNAL_ERROR.getCode(),
            e.getMessage());
      }
    }
  }
Beispiel #4
0
  public void beforeReconnect(HornetQException e) {
    logger.warn("disconnected from yamcs: {}", e.getMessage());
    for (ConnectionListener cl : connectionListeners) {
      cl.disconnected();
      cl.log(e.getMessage());
    }

    // clear all pending messages in the data consumers, as they will be re-submitted
    // by yamcs upon re-connect
    for (ClientConsumer consumer : dataConsumers) {
      try {
        MessageHandler handler = consumer.getMessageHandler();
        if (handler instanceof ClientAckMessageHandler) {
          ((ClientAckMessageHandler) handler).clearPendingMessages();
        }
      } catch (HornetQException e1) {
        // ignore
      }
    }
  }
Beispiel #5
0
 private void init() throws YamcsApiException {
   try {
     String username = null;
     String password = null;
     if (invm) {
       locator =
           HornetQClient.createServerLocatorWithoutHA(
               new TransportConfiguration(Protocol.IN_VM_FACTORY));
       sessionFactory = locator.createSessionFactory();
       username = hornetqInvmUser;
       password = hornetqInvmPass;
     } else {
       if (ycd.host != null) {
         Map<String, Object> tcpConfig = new HashMap<String, Object>();
         tcpConfig.put(TransportConstants.HOST_PROP_NAME, ycd.host);
         tcpConfig.put(TransportConstants.PORT_PROP_NAME, ycd.port);
         locator =
             HornetQClient.createServerLocatorWithoutHA(
                 new TransportConfiguration(NettyConnectorFactory.class.getName(), tcpConfig));
         sessionFactory = locator.createSessionFactory();
       } else {
         locator =
             HornetQClient.createServerLocatorWithoutHA(
                 new TransportConfiguration(NettyConnectorFactory.class.getName()));
         sessionFactory = locator.createSessionFactory();
       }
       username = ycd.username;
       password = ycd.password;
     }
     // All sessions are authenticated, a null username translates to
     // guest auth and authz (if allowed by server)
     session =
         sessionFactory.createSession(username, password, false, true, true, preAcknowledge, 1);
     session.start();
   } catch (HornetQException e) {
     // Pass specific HornetQExceptions as our cause, helps identify
     // permissions problems
     try {
       close();
     } catch (HornetQException e1) {
     }
     throw new YamcsApiException(e.getMessage(), e);
   } catch (Exception e) {
     // Pass Exception's cause as our cause.
     System.out.println(e);
     // close everything
     try {
       close();
     } catch (HornetQException e1) {
     }
     throw new YamcsApiException(e.getMessage(), e.getCause());
   }
 }
 public void writeInternal(long positionToWrite, long size, ByteBuffer bytes)
     throws HornetQException {
   try {
     writeInternal(handler, positionToWrite, size, bytes);
   } catch (HornetQException e) {
     fireExceptionListener(e.getType().getCode(), e.getMessage());
     throw e;
   }
   if (bufferCallback != null) {
     bufferCallback.bufferDone(bytes);
   }
 }
  public boolean removeMessage(final long messageID) throws Exception {
    checkStarted();

    clearIO();
    try {
      return queue.deleteReference(messageID);
    } catch (HornetQException e) {
      throw new IllegalStateException(e.getMessage());
    } finally {
      blockOnIO();
    }
  }
  public int expireMessages(final String filterStr) throws Exception {
    checkStarted();

    clearIO();
    try {
      Filter filter = FilterImpl.createFilter(filterStr);
      return queue.expireReferences(filter);
    } catch (HornetQException e) {
      throw new IllegalStateException(e.getMessage());
    } finally {
      blockOnIO();
    }
  }
 private void run() {
   try {
     if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
       HornetQServerLogger.LOGGER.debug("deleting temporary queue " + bindingName);
     }
     try {
       server.destroyQueue(bindingName, null, false);
     } catch (HornetQException e) {
       // that's fine.. it can happen due to queue already been deleted
       HornetQServerLogger.LOGGER.debug(e.getMessage(), e);
     }
   } catch (Exception e) {
     HornetQServerLogger.LOGGER.errorRemovingTempQueue(e, bindingName);
   }
 }