{"action":"created","comment":{"url":"https://api.github.com/repos/lwes/lwes-java/pulls/comments/42065955","id":42065955,"diff_hunk":"@@ -0,0 +1,278 @@\n+/*======================================================================*\n+ * Copyright (c) 2015, OpenX. All rights reserved.                      *\n+ *                                                                      *\n+ * Licensed under the New BSD License (the \"License\"); you may not use  *\n+ * this file except in compliance with the License.  Unless required    *\n+ * by applicable law or agreed to in writing, software distributed      *\n+ * under the License is distributed on an \"AS IS\" BASIS, WITHOUT        *\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.     *\n+ * See the License for the specific language governing permissions and  *\n+ * limitations under the License. See accompanying LICENSE file.        *\n+ *======================================================================*/\n+\n+package org.lwes.emitter;\n+\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+import org.lwes.Event;\n+import org.lwes.EventFactory;\n+import org.lwes.EventSystemException;\n+import org.lwes.util.NumberCodec;\n+\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.net.DatagramPacket;\n+import java.net.DatagramSocket;\n+import java.net.InetAddress;\n+\n+/**\n+ * Abstract class for emitting events on a datagram socket.\n+ *\n+ * @author      Kenneth Kharma\n+ * @since       2.1.0\n+ */\n+\n+public abstract class DatagramSocketEventEmitter<T extends DatagramSocket>\n+    extends AbstractEventEmitter {\n+\n+  private static transient Log log =\n+    LogFactory.getLog(DatagramSocketEventEmitter.class);\n+\n+  /* the socket being used */\n+  protected T socket = null;\n+\n+  /* the address */\n+  protected InetAddress address = null;\n+\n+  /* the port */\n+  protected int port = 9191;\n+\n+  /* the socket interface */\n+  protected InetAddress iface = null;\n+\n+  /* a lock variable to synchronize events */\n+  protected Object lock = new Object();\n+\n+  /**\n+   * Default constructor.\n+   */\n+  public DatagramSocketEventEmitter() {\n+  }\n+\n+  /**\n+   * Sets the destination address for this emitter.\n+   *\n+   * @param address the address\n+   *\n+   */\n+  public void setAddress(InetAddress address) {\n+    this.address = address;\n+  }\n+\n+  /**\n+   * Gets the address for this emitter.\n+   *\n+   * @return the address\n+   */\n+  public InetAddress getAddress() {\n+    return this.address;\n+  }\n+\n+  /**\n+   * Sets the destination port for this emitter.\n+   *\n+   * @param port the port\n+   *\n+   */\n+  public void setPort(int port) {\n+    this.port = port;\n+  }\n+\n+  /**\n+   * Gets the destination port for this emitter.\n+   *\n+   * @return the port\n+   */\n+  public int getPort() {\n+    return this.port;\n+  }\n+\n+  /**\n+   * Sets the network interface for this emitter.\n+   *\n+   * @param iface the network interface\n+   */\n+  public void setInterface(InetAddress iface) {\n+    this.iface = iface;\n+  }\n+\n+  /**\n+   * Gets the network interface for this emitter.\n+   *\n+   * @return the interface address\n+   */\n+  public InetAddress getInterface() {\n+    return this.iface;\n+  }\n+\n+  /**\n+   * Sets the ESF file used for event validation.\n+   * @param esfFilePath the path of the ESF file\n+   */\n+  public void setESFFilePath(String esfFilePath) {\n+    if (getFactory() != null) {\n+      getFactory().setESFFilePath(esfFilePath);\n+    }\n+  }\n+\n+  /**\n+   * Gets the ESF file used for event validation\n+   * @return the ESF file path\n+   */\n+  public String getESFFilePath() {\n+    if (getFactory() != null) {\n+      return getFactory().getESFFilePath();\n+    } else {\n+      return null;\n+    }\n+  }\n+\n+  /**\n+   * Sets an InputStream to be used for event validation.\n+   * @param esfInputStream an InputStream used for event validation\n+   */\n+  public void setESFInputStream(InputStream esfInputStream) {\n+    if (getFactory() != null) {\n+      getFactory().setESFInputStream(esfInputStream);\n+    }\n+  }\n+\n+  /**\n+   * Gets the InputStream being used for event validation.\n+   * @return the InputStream of the ESF validator\n+   */\n+  public InputStream getESFInputStream() {\n+    if (getFactory() != null) {\n+      return getFactory().getESFInputStream();\n+    } else {\n+      return null;\n+    }\n+  }\n+\n+  /**\n+   * Creates the underlying datagram socket.\n+   * @throws IOException if an I/O error occurs during socket creation.\n+   */\n+  protected abstract void createSocket() throws IOException;\n+\n+  /**\n+   * Initializes the emitter.\n+   * @throws IOException if an I/O error occurs during initialization.\n+   */\n+  @Override\n+  public void initialize() throws IOException {\n+    createSocket();\n+    super.initialize();\n+  }\n+\n+  /**\n+   * @throws IOException if an I/O error occurs on shutdown.\n+   */\n+  public void shutdown() throws IOException {\n+    // close the socket AFTER calling super shutdown since that is trying to\n+    // send a shutdown message.\n+    super.shutdown();\n+    if (socket != null) {\n+      socket.close();\n+    }\n+  }\n+\n+  /**\n+   * Creates a new event named <tt>eventName</tt>.\n+   * @param eventName the name of the event to be created\n+   * @return a new Event\n+   * @exception EventSystemException if there is a problem creating the event\n+   */\n+  public Event createEvent(String eventName) throws EventSystemException {\n+    return createEvent(eventName, true);\n+  }\n+\n+  /**\n+   * Creates a new event named <tt>eventName</tt>.\n+   * @param eventName the name of the event to be created\n+   * @param validate whether or not to validate the event against the EventTemplateDB\n+   * @return a new Event\n+   * @exception EventSystemException if there is a problem creating the event\n+   */\n+  public Event createEvent(String eventName, boolean validate) throws EventSystemException {\n+    if (getFactory() != null) {\n+      return getFactory().createEvent(eventName, validate);\n+    } else {\n+      throw new EventSystemException(\"EventFactory not initialized\");\n+    }\n+  }\n+\n+  /**\n+   * Emits the event to the network.\n+   *\n+   * @param event the event to emit\n+   * @exception IOException throws an IOException is there is a network error.\n+   * @throws EventSystemException if unable to serialize the event\n+   * @return number of bytes emitted\n+   */\n+  public int emit(Event event) throws IOException, EventSystemException {\n+    byte[] msg = event.serialize();\n+    int bytesEmitted = 0;\n+    synchronized (lock) {","path":"src/main/java/org/lwes/emitter/DatagramSocketEventEmitter.java","position":226,"original_position":226,"commit_id":"c1aa2888c6fce780483817dd31c68d3bcfbf8f0d","original_commit_id":"c1aa2888c6fce780483817dd31c68d3bcfbf8f0d","user":{"login":"nimaco","id":3443579,"avatar_url":"https://avatars.githubusercontent.com/u/3443579?v=3","gravatar_id":"","url":"https://api.github.com/users/nimaco","html_url":"https://github.com/nimaco","followers_url":"https://api.github.com/users/nimaco/followers","following_url":"https://api.github.com/users/nimaco/following{/other_user}","gists_url":"https://api.github.com/users/nimaco/gists{/gist_id}","starred_url":"https://api.github.com/users/nimaco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nimaco/subscriptions","organizations_url":"https://api.github.com/users/nimaco/orgs","repos_url":"https://api.github.com/users/nimaco/repos","events_url":"https://api.github.com/users/nimaco/events{/privacy}","received_events_url":"https://api.github.com/users/nimaco/received_events","type":"User","site_admin":false},"body":"I know this bit was in the original code, but do we really need to synchronize here?  emit basically just calls socket.send, which I think is threadsafe.  collectStatistics does stuff that doesn't appear threadsafe, so maybe there's little to gain in calling emit outside of a synchronized block.  one could probably also make collectStatistics threadsafe as well, but I'm just venturing further away from the intent of this PR.","created_at":"2015-10-14T23:10:21Z","updated_at":"2015-10-14T23:10:21Z","html_url":"https://github.com/lwes/lwes-java/pull/31#discussion_r42065955","pull_request_url":"https://api.github.com/repos/lwes/lwes-java/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/lwes/lwes-java/pulls/comments/42065955"},"html":{"href":"https://github.com/lwes/lwes-java/pull/31#discussion_r42065955"},"pull_request":{"href":"https://api.github.com/repos/lwes/lwes-java/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/lwes/lwes-java/pulls/31","id":22157389,"html_url":"https://github.com/lwes/lwes-java/pull/31","diff_url":"https://github.com/lwes/lwes-java/pull/31.diff","patch_url":"https://github.com/lwes/lwes-java/pull/31.patch","issue_url":"https://api.github.com/repos/lwes/lwes-java/issues/31","number":31,"state":"open","locked":false,"title":"added DatagramSocketEventEmitter abstract class, which UnicastEventEmitt...","user":{"login":"kkharma","id":8990623,"avatar_url":"https://avatars.githubusercontent.com/u/8990623?v=3","gravatar_id":"","url":"https://api.github.com/users/kkharma","html_url":"https://github.com/kkharma","followers_url":"https://api.github.com/users/kkharma/followers","following_url":"https://api.github.com/users/kkharma/following{/other_user}","gists_url":"https://api.github.com/users/kkharma/gists{/gist_id}","starred_url":"https://api.github.com/users/kkharma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkharma/subscriptions","organizations_url":"https://api.github.com/users/kkharma/orgs","repos_url":"https://api.github.com/users/kkharma/repos","events_url":"https://api.github.com/users/kkharma/events{/privacy}","received_events_url":"https://api.github.com/users/kkharma/received_events","type":"User","site_admin":false},"body":"...er and MulticastEventEmitter both extend\r\n\r\nUnicastEventEmitter and MulticastEventEmitter contained a lot of duplicated code.  also, UnicastEventEmitter did not extend AbstractEventEmitter for some reason, so heartbeats were not possible.  this is an attempt to clean that up.","created_at":"2014-10-02T17:48:15Z","updated_at":"2015-10-14T23:10:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"632f16b624fc23fe606301c0ee424dbb7792f7b8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/lwes/lwes-java/pulls/31/commits","review_comments_url":"https://api.github.com/repos/lwes/lwes-java/pulls/31/comments","review_comment_url":"https://api.github.com/repos/lwes/lwes-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lwes/lwes-java/issues/31/comments","statuses_url":"https://api.github.com/repos/lwes/lwes-java/statuses/c1aa2888c6fce780483817dd31c68d3bcfbf8f0d","head":{"label":"kkharma:master","ref":"master","sha":"c1aa2888c6fce780483817dd31c68d3bcfbf8f0d","user":{"login":"kkharma","id":8990623,"avatar_url":"https://avatars.githubusercontent.com/u/8990623?v=3","gravatar_id":"","url":"https://api.github.com/users/kkharma","html_url":"https://github.com/kkharma","followers_url":"https://api.github.com/users/kkharma/followers","following_url":"https://api.github.com/users/kkharma/following{/other_user}","gists_url":"https://api.github.com/users/kkharma/gists{/gist_id}","starred_url":"https://api.github.com/users/kkharma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkharma/subscriptions","organizations_url":"https://api.github.com/users/kkharma/orgs","repos_url":"https://api.github.com/users/kkharma/repos","events_url":"https://api.github.com/users/kkharma/events{/privacy}","received_events_url":"https://api.github.com/users/kkharma/received_events","type":"User","site_admin":false},"repo":{"id":24701245,"name":"lwes-java","full_name":"kkharma/lwes-java","owner":{"login":"kkharma","id":8990623,"avatar_url":"https://avatars.githubusercontent.com/u/8990623?v=3","gravatar_id":"","url":"https://api.github.com/users/kkharma","html_url":"https://github.com/kkharma","followers_url":"https://api.github.com/users/kkharma/followers","following_url":"https://api.github.com/users/kkharma/following{/other_user}","gists_url":"https://api.github.com/users/kkharma/gists{/gist_id}","starred_url":"https://api.github.com/users/kkharma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkharma/subscriptions","organizations_url":"https://api.github.com/users/kkharma/orgs","repos_url":"https://api.github.com/users/kkharma/repos","events_url":"https://api.github.com/users/kkharma/events{/privacy}","received_events_url":"https://api.github.com/users/kkharma/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kkharma/lwes-java","description":"Light Weight Event System Java library","fork":true,"url":"https://api.github.com/repos/kkharma/lwes-java","forks_url":"https://api.github.com/repos/kkharma/lwes-java/forks","keys_url":"https://api.github.com/repos/kkharma/lwes-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kkharma/lwes-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kkharma/lwes-java/teams","hooks_url":"https://api.github.com/repos/kkharma/lwes-java/hooks","issue_events_url":"https://api.github.com/repos/kkharma/lwes-java/issues/events{/number}","events_url":"https://api.github.com/repos/kkharma/lwes-java/events","assignees_url":"https://api.github.com/repos/kkharma/lwes-java/assignees{/user}","branches_url":"https://api.github.com/repos/kkharma/lwes-java/branches{/branch}","tags_url":"https://api.github.com/repos/kkharma/lwes-java/tags","blobs_url":"https://api.github.com/repos/kkharma/lwes-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kkharma/lwes-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kkharma/lwes-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/kkharma/lwes-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kkharma/lwes-java/statuses/{sha}","languages_url":"https://api.github.com/repos/kkharma/lwes-java/languages","stargazers_url":"https://api.github.com/repos/kkharma/lwes-java/stargazers","contributors_url":"https://api.github.com/repos/kkharma/lwes-java/contributors","subscribers_url":"https://api.github.com/repos/kkharma/lwes-java/subscribers","subscription_url":"https://api.github.com/repos/kkharma/lwes-java/subscription","commits_url":"https://api.github.com/repos/kkharma/lwes-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/kkharma/lwes-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/kkharma/lwes-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/kkharma/lwes-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/kkharma/lwes-java/contents/{+path}","compare_url":"https://api.github.com/repos/kkharma/lwes-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kkharma/lwes-java/merges","archive_url":"https://api.github.com/repos/kkharma/lwes-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kkharma/lwes-java/downloads","issues_url":"https://api.github.com/repos/kkharma/lwes-java/issues{/number}","pulls_url":"https://api.github.com/repos/kkharma/lwes-java/pulls{/number}","milestones_url":"https://api.github.com/repos/kkharma/lwes-java/milestones{/number}","notifications_url":"https://api.github.com/repos/kkharma/lwes-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kkharma/lwes-java/labels{/name}","releases_url":"https://api.github.com/repos/kkharma/lwes-java/releases{/id}","created_at":"2014-10-02T00:55:29Z","updated_at":"2014-10-02T17:45:54Z","pushed_at":"2015-10-13T23:45:07Z","git_url":"git://github.com/kkharma/lwes-java.git","ssh_url":"git@github.com:kkharma/lwes-java.git","clone_url":"https://github.com/kkharma/lwes-java.git","svn_url":"https://github.com/kkharma/lwes-java","homepage":"","size":1141,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"lwes:master","ref":"master","sha":"cad10f3c246b61c3ff4e51c08b407810d350224f","user":{"login":"lwes","id":638429,"avatar_url":"https://avatars.githubusercontent.com/u/638429?v=3","gravatar_id":"","url":"https://api.github.com/users/lwes","html_url":"https://github.com/lwes","followers_url":"https://api.github.com/users/lwes/followers","following_url":"https://api.github.com/users/lwes/following{/other_user}","gists_url":"https://api.github.com/users/lwes/gists{/gist_id}","starred_url":"https://api.github.com/users/lwes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lwes/subscriptions","organizations_url":"https://api.github.com/users/lwes/orgs","repos_url":"https://api.github.com/users/lwes/repos","events_url":"https://api.github.com/users/lwes/events{/privacy}","received_events_url":"https://api.github.com/users/lwes/received_events","type":"Organization","site_admin":false},"repo":{"id":1413165,"name":"lwes-java","full_name":"lwes/lwes-java","owner":{"login":"lwes","id":638429,"avatar_url":"https://avatars.githubusercontent.com/u/638429?v=3","gravatar_id":"","url":"https://api.github.com/users/lwes","html_url":"https://github.com/lwes","followers_url":"https://api.github.com/users/lwes/followers","following_url":"https://api.github.com/users/lwes/following{/other_user}","gists_url":"https://api.github.com/users/lwes/gists{/gist_id}","starred_url":"https://api.github.com/users/lwes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lwes/subscriptions","organizations_url":"https://api.github.com/users/lwes/orgs","repos_url":"https://api.github.com/users/lwes/repos","events_url":"https://api.github.com/users/lwes/events{/privacy}","received_events_url":"https://api.github.com/users/lwes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lwes/lwes-java","description":"Light Weight Event System Java library","fork":false,"url":"https://api.github.com/repos/lwes/lwes-java","forks_url":"https://api.github.com/repos/lwes/lwes-java/forks","keys_url":"https://api.github.com/repos/lwes/lwes-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lwes/lwes-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lwes/lwes-java/teams","hooks_url":"https://api.github.com/repos/lwes/lwes-java/hooks","issue_events_url":"https://api.github.com/repos/lwes/lwes-java/issues/events{/number}","events_url":"https://api.github.com/repos/lwes/lwes-java/events","assignees_url":"https://api.github.com/repos/lwes/lwes-java/assignees{/user}","branches_url":"https://api.github.com/repos/lwes/lwes-java/branches{/branch}","tags_url":"https://api.github.com/repos/lwes/lwes-java/tags","blobs_url":"https://api.github.com/repos/lwes/lwes-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lwes/lwes-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lwes/lwes-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/lwes/lwes-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lwes/lwes-java/statuses/{sha}","languages_url":"https://api.github.com/repos/lwes/lwes-java/languages","stargazers_url":"https://api.github.com/repos/lwes/lwes-java/stargazers","contributors_url":"https://api.github.com/repos/lwes/lwes-java/contributors","subscribers_url":"https://api.github.com/repos/lwes/lwes-java/subscribers","subscription_url":"https://api.github.com/repos/lwes/lwes-java/subscription","commits_url":"https://api.github.com/repos/lwes/lwes-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/lwes/lwes-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/lwes/lwes-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/lwes/lwes-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/lwes/lwes-java/contents/{+path}","compare_url":"https://api.github.com/repos/lwes/lwes-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lwes/lwes-java/merges","archive_url":"https://api.github.com/repos/lwes/lwes-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lwes/lwes-java/downloads","issues_url":"https://api.github.com/repos/lwes/lwes-java/issues{/number}","pulls_url":"https://api.github.com/repos/lwes/lwes-java/pulls{/number}","milestones_url":"https://api.github.com/repos/lwes/lwes-java/milestones{/number}","notifications_url":"https://api.github.com/repos/lwes/lwes-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lwes/lwes-java/labels{/name}","releases_url":"https://api.github.com/repos/lwes/lwes-java/releases{/id}","created_at":"2011-02-26T00:29:50Z","updated_at":"2014-11-21T13:04:13Z","pushed_at":"2015-10-13T23:45:08Z","git_url":"git://github.com/lwes/lwes-java.git","ssh_url":"git@github.com:lwes/lwes-java.git","clone_url":"https://github.com/lwes/lwes-java.git","svn_url":"https://github.com/lwes/lwes-java","homepage":"","size":1601,"stargazers_count":6,"watchers_count":6,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":4,"forks":16,"open_issues":4,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lwes/lwes-java/pulls/31"},"html":{"href":"https://github.com/lwes/lwes-java/pull/31"},"issue":{"href":"https://api.github.com/repos/lwes/lwes-java/issues/31"},"comments":{"href":"https://api.github.com/repos/lwes/lwes-java/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/lwes/lwes-java/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/lwes/lwes-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lwes/lwes-java/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/lwes/lwes-java/statuses/c1aa2888c6fce780483817dd31c68d3bcfbf8f0d"}}}}