Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AutopsyEventPublisher.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2015 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.events;
20 
21 import java.beans.PropertyChangeListener;
22 import java.net.URISyntaxException;
23 import java.util.Set;
24 import java.util.logging.Level;
25 import javax.jms.JMSException;
29 
37 public final class AutopsyEventPublisher {
38 
42  private static final Logger logger = Logger.getLogger(AutopsyEventPublisher.class.getName());
43  private static final int MAX_REMOTE_EVENT_PUBLISH_TRIES = 1;
44  private final LocalEventPublisher localPublisher;
45  private RemoteEventPublisher remotePublisher;
46  private String currentChannelName;
47 
55  localPublisher = new LocalEventPublisher();
56  }
57 
66  public void openRemoteEventChannel(String channelName) throws AutopsyEventException {
67  currentChannelName = channelName;
68  if (null != remotePublisher) {
70  }
71  try {
72  remotePublisher = new RemoteEventPublisher(channelName, localPublisher, UserPreferences.getMessageServiceConnectionInfo());
73  } catch (URISyntaxException | JMSException ex) {
74  String message = "Failed to open remote event channel"; //NON-NLS
75  logger.log(Level.SEVERE, message, ex);
76  throw new AutopsyEventException(message, ex);
77  } catch (UserPreferencesException ex) {
78  String message = "Error accessing messaging service connection info"; //NON-NLS
79  logger.log(Level.SEVERE, message, ex);
80  throw new AutopsyEventException(message, ex);
81  }
82  }
83 
88  public void closeRemoteEventChannel() {
90  currentChannelName = null;
91  }
92 
99  public void addSubscriber(Set<String> eventNames, PropertyChangeListener subscriber) {
100  localPublisher.addSubscriber(eventNames, subscriber);
101  }
102 
109  public void addSubscriber(String eventName, PropertyChangeListener subscriber) {
110  localPublisher.addSubscriber(eventName, subscriber);
111  }
112 
119  public void removeSubscriber(Set<String> eventNames, PropertyChangeListener subscriber) {
120  localPublisher.removeSubscriber(eventNames, subscriber);
121  }
122 
129  public void removeSubscriber(String eventName, PropertyChangeListener subscriber) {
130  localPublisher.removeSubscriber(eventName, subscriber);
131  }
132 
138  public void publish(AutopsyEvent event) {
139  publishLocally(event);
140  publishRemotely(event);
141  }
142 
148  public void publishLocally(AutopsyEvent event) {
149  localPublisher.publish(event);
150  }
151 
157  public void publishRemotely(AutopsyEvent event) {
158  if (null != currentChannelName) {
159  boolean published = false;
160  int tryCount = 1;
161 
162  while (false == published && tryCount <= MAX_REMOTE_EVENT_PUBLISH_TRIES) {
163  try {
164  if (null == remotePublisher) {
165  openRemoteEventChannel(currentChannelName);
166  }
167  remotePublisher.publish(event);
168  published = true;
169  } catch (AutopsyEventException | JMSException ex) {
170  logger.log(Level.SEVERE, String.format("Failed to publish %s using channel %s (tryCount = %s)", event.getPropertyName(), currentChannelName, tryCount), ex); //NON-NLS
172  ++tryCount;
173  }
174  }
175  }
176  }
177 
182  private void stopRemotePublisher() {
183  if (null != remotePublisher) {
184  try {
185  remotePublisher.stop();
186  } catch (JMSException ex) {
187  logger.log(Level.SEVERE, String.format("Error closing remote event publisher for channel %s", currentChannelName), ex); //NON-NLS
188  }
189  remotePublisher = null;
190  }
191  }
192 
193 }
void addSubscriber(Set< String > eventNames, PropertyChangeListener subscriber)
void addSubscriber(String eventName, PropertyChangeListener subscriber)
void removeSubscriber(Set< String > eventNames, PropertyChangeListener subscriber)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
void removeSubscriber(String eventName, PropertyChangeListener subscriber)
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.