View Javadoc
1   /**
2    * Copyright (C) 2010-14 pvmanager developers. See COPYRIGHT.TXT
3    * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4    */
5   package org.epics.pvmanager.jca;
6   
7   import gov.aps.jca.Channel;
8   import gov.aps.jca.dbr.DBR;
9   import gov.aps.jca.dbr.DBR_String;
10  import gov.aps.jca.dbr.DBR_TIME_String;
11  import gov.aps.jca.dbr.Severity;
12  import gov.aps.jca.dbr.Status;
13  import gov.aps.jca.dbr.TimeStamp;
14  import gov.aps.jca.event.MonitorEvent;
15  
16  /**
17   * Represent the payload produced at each monitor event, consisting of
18   * both the metadata and the event data.
19   *
20   * @author carcassi
21   */
22  public class JCAMessagePayload {
23      private final DBR metadata;
24      private final MonitorEvent event;
25  
26      JCAMessagePayload(DBR metadata, MonitorEvent event) {
27          if (event != null) {
28              // If we have a monitor event, it may be an "incomplete"
29              // String event because of the RTYP support
30              if (event.getDBR() instanceof DBR_String && !(event.getDBR() instanceof DBR_TIME_String)) {
31                  DBR_String originalValue = (DBR_String) event.getDBR();
32                  // Received only partial data. Filling in time and alarm
33                  DBR_TIME_String value = new DBR_TIME_String(originalValue.getStringValue());
34                  value.setSeverity(Severity.NO_ALARM);
35                  value.setStatus(Status.NO_ALARM);
36                  value.setTimeStamp(new TimeStamp());
37  
38                  event = new MonitorEvent((Channel) event.getSource(), value, event.getStatus());
39              }
40          }
41          this.metadata = metadata;
42          this.event = event;
43      }
44  
45      /**
46       * The event returned by the monitor.
47       * 
48       * @return the monitor event
49       */
50      public MonitorEvent getEvent() {
51          return event;
52      }
53  
54      /**
55       * The data taken with a GET at connection time.
56       * 
57       * @return the dbr type for the metadata
58       */
59      public DBR getMetadata() {
60          return metadata;
61      }
62  
63      @Override
64      public String toString() {
65          DBR value = null;
66          if (event != null) {
67              value = event.getDBR();
68          }
69          return "Metadata " + metadata + " value " + value;
70      }
71      
72  }