test_class.declarator: metric = new MetricRegistry()
test_class.modifier: @Spy
      private
test_class.original_string: @Spy
      private MetricRegistry metric = new MetricRegistry();
test_class.type: MetricRegistry
test_class.var_name: metric
test_class.declarator: svc = new XMPPMsgService(metric)
test_class.modifier: @InjectMocks
      private
test_class.original_string: @InjectMocks
      private XMPPMsgService svc = new XMPPMsgService(metric);
test_class.type: XMPPMsgService
test_class.var_name: svc
test_class.declarator: timeout = Integer.MAX_VALUE
test_class.modifier: private static final
test_class.original_string: private static final int timeout = Integer.MAX_VALUE;
test_class.type: int
test_class.var_name: timeout
test_class.file: antenna/src/test/java/com/oneops/antenna/senders/generic/XMPPMsgServiceTest.java
test_class.identifier: XMPPMsgServiceTest
test_case.body: @Test(expectedExceptions = ClassCastException.class)
      public void negativeCastTest() throws Exception {
          this.svc.postMessage(new NotificationMessage(), new EmailSubscriber());
      }
test_case.class_method_signature: XMPPMsgServiceTest.negativeCastTest()
test_case.full_signature: @Test(expectedExceptions = ClassCastException.class) public void negativeCastTest()
test_case.identifier: negativeCastTest
test_case.invocations: postMessage
test_case.modifiers: @Test(expectedExceptions = ClassCastException.class) public
test_case.parameters: ()
test_case.return: void
test_case.signature: void negativeCastTest()
focal_class.declarator: logger = Logger.getLogger(XMPPMsgService.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = Logger.getLogger(XMPPMsgService.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy")
focal_class.modifier: private final
focal_class.original_string: private final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
focal_class.type: SimpleDateFormat
focal_class.var_name: dateFormat
focal_class.declarator: connCache = new ConcurrentHashMap<>()
focal_class.modifier: private
focal_class.original_string: private ConcurrentMap<ChatPresence, ChatRoomConnection> connCache = new ConcurrentHashMap<>();
focal_class.type: ConcurrentMap<ChatPresence, ChatRoomConnection>
focal_class.var_name: connCache
focal_class.declarator: botName
focal_class.modifier: private
focal_class.original_string: private String botName;
focal_class.type: String
focal_class.var_name: botName
focal_class.declarator: timeout
focal_class.modifier: private
focal_class.original_string: private int timeout;
focal_class.type: int
focal_class.var_name: timeout
focal_class.declarator: timesConnecting = 0
focal_class.modifier: private
focal_class.original_string: private int timesConnecting = 0;
focal_class.type: int
focal_class.var_name: timesConnecting
focal_class.declarator: metrics
focal_class.modifier: private final
focal_class.original_string: private final MetricRegistry metrics;
focal_class.type: MetricRegistry
focal_class.var_name: metrics
focal_class.declarator: xmpp
focal_class.modifier: private
focal_class.original_string: private Meter xmpp;
focal_class.type: Meter
focal_class.var_name: xmpp
focal_class.declarator: xmppErr
focal_class.modifier: private
focal_class.original_string: private Meter xmppErr;
focal_class.type: Meter
focal_class.var_name: xmppErr
focal_class.file: antenna/src/main/java/com/oneops/antenna/senders/generic/XMPPMsgService.java
focal_class.identifier: XMPPMsgService
focal_class.interfaces: implements NotificationSender
focal_class.class_method_signature: XMPPMsgService.XMPPMsgService(MetricRegistry metrics)
focal_class.full_signature: @Autowired public  XMPPMsgService(MetricRegistry metrics)
focal_class.identifier: XMPPMsgService
focal_class.modifiers: @Autowired public
focal_class.parameters: (MetricRegistry metrics)
focal_class.signature:  XMPPMsgService(MetricRegistry metrics)
focal_class.class_method_signature: XMPPMsgService.init()
focal_class.full_signature: @PostConstruct public void init()
focal_class.identifier: init
focal_class.modifiers: @PostConstruct public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void init()
focal_class.class_method_signature: XMPPMsgService.postMessage(NotificationMessage msg, BasicSubscriber sub)
focal_class.full_signature: @Override public boolean postMessage(NotificationMessage msg, BasicSubscriber sub)
focal_class.identifier: postMessage
focal_class.modifiers: @Override public
focal_class.parameters: (NotificationMessage msg, BasicSubscriber sub)
focal_class.return: boolean
focal_class.signature: boolean postMessage(NotificationMessage msg, BasicSubscriber sub)
focal_class.class_method_signature: XMPPMsgService.linkifyUrl(String hyperlinkText, URL url)
focal_class.full_signature: private String linkifyUrl(String hyperlinkText, URL url)
focal_class.identifier: linkifyUrl
focal_class.modifiers: private
focal_class.parameters: (String hyperlinkText, URL url)
focal_class.return: String
focal_class.signature: String linkifyUrl(String hyperlinkText, URL url)
focal_class.class_method_signature: XMPPMsgService.getBotName()
focal_class.full_signature: public String getBotName()
focal_class.identifier: getBotName
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getBotName()
focal_class.class_method_signature: XMPPMsgService.setBotName(String botName)
focal_class.full_signature: public void setBotName(String botName)
focal_class.identifier: setBotName
focal_class.modifiers: public
focal_class.parameters: (String botName)
focal_class.return: void
focal_class.signature: void setBotName(String botName)
focal_class.class_method_signature: XMPPMsgService.getTimeout()
focal_class.full_signature: public int getTimeout()
focal_class.identifier: getTimeout
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getTimeout()
focal_class.class_method_signature: XMPPMsgService.setTimeout(int timeout)
focal_class.full_signature: public void setTimeout(int timeout)
focal_class.identifier: setTimeout
focal_class.modifiers: public
focal_class.parameters: (int timeout)
focal_class.return: void
focal_class.signature: void setTimeout(int timeout)
focal_class.class_method_signature: XMPPMsgService.finalize()
focal_class.full_signature: @Override protected void finalize()
focal_class.identifier: finalize
focal_class.modifiers: @Override protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void finalize()
focal_method.body: @Override
      public boolean postMessage(NotificationMessage msg, BasicSubscriber sub) {
  
          if (msg == null) throw new IllegalArgumentException("XMPP notification msg is null");
          XMPPSubscriber xmppSub = (XMPPSubscriber) sub;
  
          String[] nsParts = msg.getNsPath().split("/");
          String orgName = nsParts[1];
  
          ChatPresence presence = new ChatPresence(xmppSub.getChatServer(),
                  xmppSub.getChatPort(),
                  xmppSub.getChatConference(),
                  xmppSub.getChatRoom(),
                  xmppSub.getChatUser(),
                  orgName);
  
          MultiUserChat ourRoom = null;
          if (connCache.containsKey(presence)) {
              if (connCache.get(presence).getConnection().isConnected()) {
                  if (connCache.get(presence).getMultiUserChat().isJoined()) {
                      ourRoom = connCache.get(presence).getMultiUserChat();
                      logger.debug("Reusing old connection. Using chat room " + presence);
                  } else {
                      logger.debug("Old connection is alive but no longer in room. Disconnecting " + presence);
                      connCache.get(presence).getConnection().disconnect();
                      // Assume conn has timed-out, disconnect and throw it away
                      connCache.remove(presence);
                  }
              } else {
                  logger.debug("Old connection we held no longer connected " + presence);
                  connCache.remove(presence);
              }
          } else {
              logger.info("Have no usable saved xmpp connections for " + presence);
          }
  
          Connection xmppConn = null;
          if (ourRoom == null) {
              try {
                  ConnectionConfiguration config = new ConnectionConfiguration(
                          xmppSub.getChatServer(), xmppSub.getChatPort());
                  config.setRosterLoadedAtLogin(false);
                  config.setSendPresence(false);
  
                  xmppConn = new XMPPConnection(config);
                  String identity = orgName + "-" + xmppSub.getName();
                  logger.info("Creating new xmpp connection. Identity= "
                          + identity + ": " + ++timesConnecting + ", " + presence);
                  xmppConn.connect();
                  /*
                   * Simultaneous logins are ok for one account if you pass a
                   * unique 3rd value here typically this for one person with
                   * more than one device like home,work,tablet etc.
                   */
                  xmppConn.login(xmppSub.getChatUser(), xmppSub.getChatPassword(), identity);
                  ourRoom = new MultiUserChat(xmppConn, xmppSub.getChatRoom()
                          + "@" + xmppSub.getChatConference());
                  /*
                   * Default config used here as we want any new room open
                   * to public. No password supplied, and no history wanted.
                   */
                  ourRoom.join(botName, null, null, timeout);
                  logger.debug("Sending the configuration form now. " +
                          "This should unlock the room for any other users to see.");
                  try {
                      ourRoom.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
                  } catch (XMPPException e) {
                      logger.debug("Registering new room threw exception, but continuing." +
                              "Another thread may have beat us, its ok", e);
                  }
  
                  ChatRoomConnection crs = this.connCache.putIfAbsent(presence,
                          new ChatRoomConnection(ourRoom, xmppConn));
                  if (crs == null) {
                      logger.debug("Have set-up and saved conn: " + presence
                              + " using resource name: " + identity
                              + " to this map for reuse: " + this.connCache);
                  } else {
                      xmppConn.disconnect();
                      logger.debug("When saving connection it was already there: " + this.connCache);
                  }
  
              } catch (XMPPException xe) {
                  xmppErr.mark();
                  logger.warn("Could not connect to xmpp chat: " + presence, xe);
                  // Disconnect to avoid connection leak.
                  if (xmppConn != null) {
                      xmppConn.disconnect();
                  }
                  return false;
              }
          }
  
          try {
              // Flavor #1 plain text
              StringBuilder plainMsg = new StringBuilder(msg.getSeverity().getName().toUpperCase());
              String msgTimeStamp = dateFormat.format(new Date(msg.getTimestamp()));
              plainMsg.append(" | ")
                      .append(msg.getType().getName())
                      .append(" | ")
                      .append(msgTimeStamp)
                      .append(" | ")
                      .append(msg.getNsPath())
                      .append("<br>")
                      .append(msg.getSubject())
                      .append("<br>")
                      .append(msg.getText());
  
              // Flavor #2 XHTML
              StringBuilder fmtMsg = new StringBuilder();
  
              URL url = URLUtil.getNotificationUrl(msg);
              fmtMsg.append("<body>")
                      .append(msg.getSeverity().getName().toUpperCase())
                      .append(" | ")
                      .append(msg.getType().getName())
                      .append(" | ")
                      .append(msgTimeStamp).append(" | ")
                      .append((url != null ? linkifyUrl(msg.getNsPath(), url) : "_" + msg.getNsPath()))
                      .append("<br/>")
                      .append(msg.getText())
                      .append("</body>");
  
              Message packetMessage = ourRoom.createMessage();
              packetMessage.setSubject(msg.getSubject());
              packetMessage.setBody(plainMsg.toString());
              // Create a XHTMLExtension Package.
              XHTMLExtension xhtmlExtension = new XHTMLExtension();
              xhtmlExtension.addBody(fmtMsg.toString());
              packetMessage.addExtension(xhtmlExtension);
              ourRoom.sendMessage(packetMessage);
              logger.debug("Message has been sent to chat room: "
                      + xmppSub.getChatRoom() + ", msg: " + plainMsg);
          } catch (XMPPException e) {
              logger.warn("Could not send xmpp message to chat: " + presence, e);
              xmppErr.mark();
              return false;
          }
  
          xmpp.mark();
          return true;
      }
focal_method.class_method_signature: XMPPMsgService.postMessage(NotificationMessage msg, BasicSubscriber sub)
focal_method.full_signature: @Override public boolean postMessage(NotificationMessage msg, BasicSubscriber sub)
focal_method.identifier: postMessage
focal_method.invocations: split getNsPath getChatServer getChatPort getChatConference getChatRoom getChatUser containsKey isConnected getConnection get isJoined getMultiUserChat get getMultiUserChat get debug debug disconnect getConnection get remove debug remove info getChatServer getChatPort setRosterLoadedAtLogin setSendPresence getName info connect login getChatUser getChatPassword getChatRoom getChatConference join debug sendConfigurationForm debug putIfAbsent debug disconnect debug mark warn disconnect toUpperCase getName getSeverity format getTimestamp append append append append append append append append append append getName getType getNsPath getSubject getText getNotificationUrl append append append append append append append append append append append toUpperCase getName getSeverity getName getType linkifyUrl getNsPath getNsPath getText createMessage setSubject getSubject setBody toString addBody toString addExtension sendMessage debug getChatRoom warn mark mark
focal_method.modifiers: @Override public
focal_method.parameters: (NotificationMessage msg, BasicSubscriber sub)
focal_method.return: boolean
focal_method.signature: boolean postMessage(NotificationMessage msg, BasicSubscriber sub)