1 /*
2 * $HeadURL: $
3 * $Date: $
4 * $Revision: $
5 * $Author: $
6 *
7 * Copyright (c) 2005 MindTree Consulting Ltd.
8 *
9 * This file is part of Insight.
10 *
11 * Insight is free software: you can redistribute it and/or modify it under the
12 * terms of the GNU General Public License as published by the Free Software
13 * Foundation, either version 3 of the License, or (at your option) any later
14 * version.
15 *
16 * Insight is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * Insight. If not, see <http://www.gnu.org/licenses/>.
23 */
24 package com.mindtree.techworks.insight.spi;
25
26 import java.io.Serializable;
27
28 import com.mindtree.techworks.insight.model.ReceiverFormat;
29
30 /**
31 *
32 * The <code>LogNamespace</code> class qualifies the LogEvent class instance
33 * with information that identifies the namespace of the instance.
34 * The namespace information can be the file name, IP address and port number e.t.c.
35 * depending on the source of the LogEvent.
36 *
37 * @author Regunath B
38 * @version 1.0, 04/12/16
39 * @see com.mindtree.techworks.insight.spi.LogEvent
40 */
41 public class LogNamespace implements Serializable {
42
43 /**
44 * Used for object serialization
45 */
46 private static final long serialVersionUID = 1148642272921507002L;
47
48 /**
49 * Variable that contains the string representation of event source
50 */
51 private String sourceString;
52
53 /**
54 * The local URL of the sourceString, if any
55 */
56 private String localSourceString;
57
58 /**
59 * The ReceiverFormat
60 */
61 private ReceiverFormat[] receiverFormat;
62
63 /*
64 * The node id of this namespace
65 */
66 private String nodeId;
67
68 /**
69 * Constructor for this class.
70 * @param sourceString the event source string
71 * @param localSourceString null or the local source string
72 * @param receiverFormat the ReceiverFormat for this LogNamespace
73 * @param nodeId the Node if where the events originated
74 */
75 public LogNamespace(String sourceString, String localSourceString, ReceiverFormat[] receiverFormat, String nodeId) {
76 this.sourceString = sourceString;
77 this.localSourceString = localSourceString;
78 this.receiverFormat = receiverFormat;
79 this.nodeId = nodeId;
80 }
81
82 /**
83 * Returns the namespace details as a string of te form: [nodeId] sourceString
84 * @return Returns the namespaceAsString.
85 */
86 public String getNamespaceAsString() {
87 return "[" + this.nodeId + "] " + this.sourceString;
88 }
89
90 /**
91 * Overriden superclass method
92 * @param the namespace that needs to be evaluated for equals
93 */
94 public boolean equals(Object namespace) {
95 if (this == namespace) {
96 return true;
97 }
98
99 if (namespace instanceof LogNamespace) {
100 LogNamespace otherNamespace = (LogNamespace)namespace;
101 // check for the source string equals
102 if ((this.sourceString != null && otherNamespace.sourceString == null) ||
103 (otherNamespace.sourceString != null && this.sourceString == null)) {
104 return false;
105 }
106 if (this.sourceString != null && otherNamespace.sourceString != null
107 && !this.sourceString.equals(otherNamespace.sourceString)) {
108 return false;
109 }
110 // check for the nodeId string equals
111 if ((this.nodeId != null && otherNamespace.nodeId == null) ||
112 (otherNamespace.nodeId != null && this.nodeId == null)) {
113 return false;
114 }
115 if (this.nodeId != null && otherNamespace.nodeId != null && !this.nodeId.equals(otherNamespace.nodeId)) {
116 return false;
117 }
118 }
119 return true;
120 }
121
122 /**
123 * @return Returns the nodeId.
124 */
125 public String getNodeId() {
126 return nodeId;
127 }
128
129 /**
130 * @return Returns the receiverFormat.
131 */
132 public ReceiverFormat[] getReceiverFormat() {
133 return receiverFormat;
134 }
135
136
137 /**
138 * @return Returns the sourceString.
139 */
140 public String getSourceString() {
141 return sourceString;
142 }
143
144 /**
145 * @return Returns the localSourceString.
146 */
147 public String getLocalSourceString() {
148 return localSourceString;
149 }
150 }