Package uk.org.microbase.notification.db.data

Examples of uk.org.microbase.notification.db.data.Message


      throws DBException
  {
    long expires = Long.MAX_VALUE;
    long now = System.currentTimeMillis();

    Message message = new Message();
    message.setContent(content);
    message.setBinaryContent(binaryContent);
    message.setExpiresTimestamp(expires);
    message.setGuid(UidGenerator.generateUid());
    message.setPublishedTimestamp(now);
    message.setPublisherGuid(publisherGuid);
    message.setTopicGuid(topicGuid);
   

    lock.acquireLock();
    try
    {
View Full Code Here


      throws DBException
  {
    lock.acquireLock();
    try
    {
      Message msg = getMessage(messageId);
      if (msg == null)
      {
        throw new DBException("No such message: "+messageId);
      }

      msg.getMetaTags().put(key, value);
      save(msg);
    }
    finally
    {
      lock.releaseLock();
View Full Code Here

      throws DBException
  {
    lock.acquireLock();
    try
    {
      Message msg = getMessage(messageId);
      if (msg == null)
      {
        throw new DBException("No such message: "+messageId);
      }

      msg.getResponderStates().put(responderId, state);
      save(msg);
    }
    finally
    {
      lock.releaseLock();
View Full Code Here

      List<Message> docs = new ArrayList<Message>();
      long lastTimestamp = Long.MIN_VALUE;
      while (cursor.hasNext())
      {
        DBObject next = cursor.next();
        Message message = deserialise(next, Message.class, true);

        if (docs.size() >= preferredLimit &&
            lastTimestamp != message.getPublishedTimestamp())
        {
          break;
        }
        else
        {
          docs.add(message);
          lastTimestamp = message.getPublishedTimestamp();
        }
      }
      return docs;
    }
    catch(Exception e)
View Full Code Here

  {
    String messageId = line.getOptionValue("message");
    try
    {
      logger.info("Searching for message: "+messageId);
      Message msg = messageDao.getMessage(messageId);
      logger.info("Got object: "+msg);
    }
    catch (DBException ex)
    {
      Logger.getLogger(NotificationClient.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

  protected Set<Message> generateWork(Message incoming)
  {
    System.out.println("Creating work...");
    Set<Message> jobs = new HashSet<Message>();

    Message newJob = new Message();
    newJob.setGuid("new job - "+System.currentTimeMillis());
    newJob.setPublisherGuid(HelloWorldLoadMonitor.class.getName());
    newJob.setTopicGuid(JOB_TOPIC);
    newJob.setUserDescription("Some description...");
    newJob.setPublishedTimestamp(System.currentTimeMillis());
    newJob.getContent().put("foo", "bar = "+System.currentTimeMillis());

    jobs.add(newJob);

    System.out.println("Generated: "+jobs.size()+" jobs");
    return jobs;
View Full Code Here

      throws MessageProcessingException
  {
    System.out.println("Creating work...");
    Set<Message> jobs = new HashSet<Message>();

    Message newJob = new Message();
    newJob.setGuid("new job - "+System.currentTimeMillis());
    newJob.setPublisherGuid(RESPONDER_ID);
    newJob.setTopicGuid(JOB_NOTIFICATION_TOPIC);
    newJob.setUserDescription("Some description...");
    newJob.setPublishedTimestamp(System.currentTimeMillis());
    newJob.getContent().put("foo", "bar = "+System.currentTimeMillis());

    jobs.add(newJob);

    System.out.println("Generated: "+jobs.size()+" jobs");
    return jobs;
View Full Code Here


  @Override
  public void run()
  {
    Message msg = null;
    try
    {
      logger.log(Level.INFO,
          "Responder compute implementation starting: {0}", responderId);

      hostname = getRuntime().getNodeInfo().getHostname();
//      responderId = getProcess().getResponder().getTaskTypeGuid();

      /*
       * Responder-specific job queue
       */
      queue = new JobQueue(responderId);

      //Local reference to central message database
      messageDao = getRuntime().getMessageDao();

      //Responder-specific message processing log
      processingLog = new MessageStateLogImpl(getRuntime().getNotificationDB());

      queue.acquireLock();
      try
      {
        //Determine if any work is available
        msg = queue.poll();
        if (msg == null)
        {
          logger.log(Level.INFO,
              "Responder: {0}: no work available. Quitting.", responderId);
          return;
        }

        //If a job was aquired from the queue, then mark it as PROCESSING
        logger.log(Level.INFO, "Responder: {0}: acquired job from queue: {1}",
            new Object[]{responderId, msg.getGuid()});
        updateMessageState(msg, State.PROCESSING);
      }
      finally
      {
        queue.releaseLock();
      }
    }
    /*
     * Any Exceptions that occur are NOT the job implementation's fault - they
     * are a Microbase problem.
     */
    catch (MessageStateLogException e)
    {
      logger.log(Level.INFO,
          "Responder: {0} failed to update state flag for message:{1}",
          new Object[]{responderId, msg.getGuid()});
      e.printStackTrace();
    }
    catch (DBException e)
    {
      logger.log(Level.INFO,
          "Responder: {0} failed to update state flag for message:{1}",
          new Object[]{responderId, msg.getGuid()});
      e.printStackTrace();
    }
    catch(Exception e)
    {
      logger.log(Level.INFO,
          "Responder: {0} failed for an unanticipated reason", responderId);
      e.printStackTrace();
    }
     
    /*
     * Now actually process the message
     */
    try
    {
      try
      {
        logger.log(Level.INFO,
            "Responder: {0}: checking job for incomplete results and "
            + "performing cleanup as required: {1}",
            new Object[]{responderId, msg.getGuid()});
        cleanupPreviousResults(msg);
        logger.log(Level.INFO, "Responder: {0}: processing job: {1}",
            new Object[]{responderId, msg.getGuid()});
        processMessage(msg);

        logger.log(Level.INFO, "Responder: {0}: marking job complete: {1}",
            new Object[]{responderId, msg.getGuid()});
        updateMessageState(msg, State.FINISHED_SUCCEEDED);
        publishSuccessMessage(msg);
        logger.log(Level.INFO, "Responder: {0}: finished with job: {1}",
            new Object[]{responderId, msg.getGuid()});
      }
      /*
       * Message processing failed.
       * Most problems here are likely to do with the job implementation
       * itself rather than Microbase
       */
      catch(MessageProcessingException e)
      {
        logger.log(Level.INFO,
            "Responder: {0}: cleanup OR processing failed for message: {1}",
            new Object[]{responderId, msg.getGuid()});
        e.printStackTrace();

        formatErrorAndPublishFailure(msg, e);
      }
      catch(Error e)
      {
        logger.log(Level.INFO,
            "Responder: {0}: cleanup OR processing failed for message: {1} "
            + "due to an Error, rather than a typical "
            + MessageProcessingException.class.getName()
            +". Please ensure that your environment is configured correctly, "
            + "including checking sufficient RAM is available, correct classes "
            + "and/or jars are available, etc.",
            new Object[]{responderId, msg.getGuid()});
        e.printStackTrace();
        formatErrorAndPublishFailure(msg, e);
      }
    }
    /*
     * Some Microbase process failed
     */
    catch (MessageStateLogException e)
    {
      logger.log(Level.INFO,
          "Responder: {0} failed to update state flag for message:{1}",
          new Object[]{responderId, msg.getGuid()});
      e.printStackTrace();
    }
    catch (DBException e)
    {
      logger.log(Level.INFO,
          "Responder: {0} either failed to update a message''s state({1}"
          +"), or failed to publish a "
          + "success / failure message. See stack trace for details.",
          new Object[]{responderId, msg.getGuid()});
      e.printStackTrace();
    }
    catch(Exception e)
    {
      logger.log(Level.INFO,
View Full Code Here

      logger.log(Level.INFO,
          "Responder: {0} now processing incoming message: {1}",
          new Object[]{responderId, msgId});

     
      Message msg = messageDao.getMessage(msgId);
      //Check whether the message is in an inconsistent state
     
      //FIXME: not sure we should be using the log here - use message annotations instead
      //State state = processingLog.getCurrentStateFor(msgId);
      /*
       * TODO do we need to lock the message? Probably not, if anything just
       * need to lock message/responder combo?
       * And probably don't even need to do that because the queue is already
       * locked (see run() method).
       */
      State state = msg.getResponderStates().get(responderId);

      if (state == null)
      {
        updateMessageState(msg, Message.State.NEW);
        state = Message.State.NEW;
      }

      switch(state)
      {
        case NEW:
        case READY:
          numJobMessagesCreated += createWorkUnits(messageDao, msg);
          break;
        case PROCESSING:
          logger.log(Level.INFO, "Not processing message: {0} because it is "
              + "already being processed", msg.getGuid());
          break;
        case ERROR_TIMEOUT:
        case ERROR_FAILED:
          logger.log(Level.INFO,
              "Not processing incomplete message: {0} because it is in error "
View Full Code Here

            new Object[]{responderId, queue.size(), maxQueueSize});
        break;
      }

      //For each message, add to queue
      Message msg = messageDao.getMessage(msgId);

      //Add messages to in-memory Hazelcast queue for this responder
      if (!queue.contains(msg))
      {
        logger.log(Level.INFO,
            "Putting message: {0} into the queue for responder: {1}. "
            + "Current queue size: {2}",
            new Object[]{msg.getGuid(), responderId, queue.size()});
        try
        {
          queue.put(msg);
        }
        catch (InterruptedException ex)
View Full Code Here

TOP

Related Classes of uk.org.microbase.notification.db.data.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.