Autopsy  4.9.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-2017 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.annotation.concurrent.GuardedBy;
26 import javax.annotation.concurrent.ThreadSafe;
27 import javax.jms.JMSException;
31 
39 @ThreadSafe
40 public final class AutopsyEventPublisher {
41 
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; // LocalEventPublisher is thread-safe
45  @GuardedBy("this)")
46  private RemoteEventPublisher remotePublisher;
47  @GuardedBy("this)")
48  private String currentChannelName;
49 
57  localPublisher = new LocalEventPublisher();
58  }
59 
68  public synchronized void openRemoteEventChannel(String channelName) throws AutopsyEventException {
69  currentChannelName = channelName;
70  if (null != remotePublisher) {
72  }
73  try {
74  remotePublisher = new RemoteEventPublisher(channelName, localPublisher, UserPreferences.getMessageServiceConnectionInfo());
75  } catch (URISyntaxException | JMSException ex) {
76  String message = "Failed to open remote event channel"; //NON-NLS
77  logger.log(Level.SEVERE, message, ex);
78  throw new AutopsyEventException(message, ex);
79  } catch (UserPreferencesException ex) {
80  String message = "Error accessing messaging service connection info"; //NON-NLS
81  logger.log(Level.SEVERE, message, ex);
82  throw new AutopsyEventException(message, ex);
83  }
84  }
85 
90  public synchronized void closeRemoteEventChannel() {
92  currentChannelName = null;
93  }
94 
101  public void addSubscriber(Set<String> eventNames, PropertyChangeListener subscriber) {
102  localPublisher.addSubscriber(eventNames, subscriber);
103  }
104 
111  public void addSubscriber(String eventName, PropertyChangeListener subscriber) {
112  localPublisher.addSubscriber(eventName, subscriber);
113  }
114 
121  public void removeSubscriber(Set<String> eventNames, PropertyChangeListener subscriber) {
122  localPublisher.removeSubscriber(eventNames, subscriber);
123  }
124 
131  public void removeSubscriber(String eventName, PropertyChangeListener subscriber) {
132  localPublisher.removeSubscriber(eventName, subscriber);
133  }
134 
140  public void publish(AutopsyEvent event) {
141  publishLocally(event);
142  publishRemotely(event);
143  }
144 
150  public void publishLocally(AutopsyEvent event) {
151  localPublisher.publish(event);
152  }
153 
159  public synchronized void publishRemotely(AutopsyEvent event) {
160  if (null != currentChannelName) {
161  boolean published = false;
162  int tryCount = 1;
163 
164  while (false == published && tryCount <= MAX_REMOTE_EVENT_PUBLISH_TRIES) {
165  try {
166  if (null == remotePublisher) {
168  }
169  remotePublisher.publish(event);
170  published = true;
171  } catch (AutopsyEventException | JMSException ex) {
172  logger.log(Level.SEVERE, String.format("Failed to publish %s using channel %s (tryCount = %s)", event.getPropertyName(), currentChannelName, tryCount), ex); //NON-NLS
174  ++tryCount;
175  }
176  }
177  }
178  }
179 
184  private synchronized void stopRemotePublisher() {
185  if (null != remotePublisher) {
186  try {
187  remotePublisher.stop();
188  } catch (JMSException ex) {
189  logger.log(Level.SEVERE, String.format("Error closing remote event publisher for channel %s", currentChannelName), ex); //NON-NLS
190  }
191  remotePublisher = null;
192  }
193  }
194 
195 }
void addSubscriber(Set< String > eventNames, PropertyChangeListener subscriber)
synchronized void openRemoteEventChannel(String channelName)
void addSubscriber(String eventName, PropertyChangeListener subscriber)
void removeSubscriber(Set< String > eventNames, PropertyChangeListener subscriber)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
synchronized void publishRemotely(AutopsyEvent event)
void removeSubscriber(String eventName, PropertyChangeListener subscriber)
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.