summaryrefslogtreecommitdiff
path: root/orktrack/src/net/sf/oreka/orktrack/messages/MetadataMessage.java
blob: e8847ba8101d7fd4358afef8b52b77378c544d4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

package net.sf.oreka.orktrack.messages;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.Transaction;

import net.sf.oreka.OrkException;
import net.sf.oreka.Direction;
import net.sf.oreka.HibernateManager;
import net.sf.oreka.messages.AsyncMessage;
import net.sf.oreka.messages.SimpleResponseMessage;
import net.sf.oreka.messages.SyncMessage;
import net.sf.oreka.orktrack.LogManager;
import net.sf.oreka.orktrack.Port;
import net.sf.oreka.orktrack.PortManager;
import net.sf.oreka.orktrack.ServiceManager;
import net.sf.oreka.orktrack.messages.TapeMessage.CaptureStage;
import net.sf.oreka.persistent.Service;
import net.sf.oreka.serializers.OrkSerializer;
import net.sf.oreka.serializers.SingleLineSerializer;

public class MetadataMessage  extends SyncMessage {

	Logger log = null;
	
	CaptureStage stage = CaptureStage.UNKN;
	int timestamp = 0;
	int duration = 0;
	String capturePort = "";
	String localParty = "";
	String localEntryPoint = "";
	String remoteParty = "";
	Direction direction = Direction.UNKN;
	String loginString = "";
	String service = "";
	
	public MetadataMessage() {
		log = LogManager.getInstance().getPortLogger();
	}
	
	@Override
	public AsyncMessage process() {
		
		SimpleResponseMessage response = new SimpleResponseMessage();
		Session session = null;
		Transaction tx = null;
		try {
			session = HibernateManager.getSession();
	        tx = session.beginTransaction();
	        boolean success = false;
	        
	        SingleLineSerializer ser = new SingleLineSerializer();
	        log.info("Message: " + ser.serialize(this));
	        
			Service service = ServiceManager.retrieveByName(this.service, session);
			
			if (service != null) {
				Port port = PortManager.instance().getAndCreatePort(this.getCapturePort(), session, service);
				port.notifyMetadataMessage(this, session, service);
				success = true;
			}
			else {
				response.setComment("service:" + this.service + " does not exist");
				log.error("MetadataMessage.process: service" + this.service + " does not exist");
			}
			
			response.setSuccess(success);
			if (success) {tx.commit();}
			else {tx.rollback();}
		}
		catch (Exception e) {
			if (tx != null) {tx.rollback();}
			log.error("TapeMessage.process: ", e);
			response.setSuccess(false);
			response.setComment(e.getMessage());
		}
		finally {
			if(session != null) {session.close();}
		}
		return response;
	}

	public void define(OrkSerializer serializer) throws OrkException {
		
		stage = (CaptureStage)serializer.enumValue("stage", stage, true);
		timestamp = serializer.intValue("timestamp", timestamp, true);
		duration = serializer.intValue("duration", duration, false);
		capturePort = serializer.stringValue("capturePort", capturePort, true);
		localParty = serializer.stringValue("localParty", localParty, false);
		localEntryPoint = serializer.stringValue("localEntryPoint", localEntryPoint, false);
		remoteParty = serializer.stringValue("remoteParty", remoteParty, false);
		direction = (Direction)serializer.enumValue("direction", direction, false);
		loginString = serializer.stringValue("loginString", loginString, false);
		service = serializer.stringValue("service", service, true);
	}

	public String getOrkClassName() {
		return "metadata";
	}

	public void validate() {
		// TODO Auto-generated method stub
		
	}

	public String getCapturePort() {
		return capturePort;
	}

	public void setCapturePort(String capturePort) {
		this.capturePort = capturePort;
	}

	public Direction getDirection() {
		return direction;
	}

	public void setDirection(Direction direction) {
		this.direction = direction;
	}

	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public String getLocalEntryPoint() {
		return localEntryPoint;
	}

	public void setLocalEntryPoint(String localEntryPoint) {
		this.localEntryPoint = localEntryPoint;
	}

	public String getLocalParty() {
		return localParty;
	}

	public void setLocalParty(String localParty) {
		this.localParty = localParty;
	}

	public Logger getLog() {
		return log;
	}

	public void setLog(Logger log) {
		this.log = log;
	}

	public String getLoginString() {
		return loginString;
	}

	public void setLoginString(String loginString) {
		this.loginString = loginString;
	}

	public String getRemoteParty() {
		return remoteParty;
	}

	public void setRemoteParty(String remoteParty) {
		this.remoteParty = remoteParty;
	}

	public String getService() {
		return service;
	}

	public void setService(String service) {
		this.service = service;
	}

	public CaptureStage getStage() {
		return stage;
	}

	public void setStage(CaptureStage stage) {
		this.stage = stage;
	}

	public int getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(int timestamp) {
		this.timestamp = timestamp;
	}

}