Line 14... |
Line 14... |
14 |
* limitations under the License.
|
14 |
* limitations under the License.
|
15 |
*/
|
15 |
*/
|
Line 16... |
Line 16... |
16 |
|
16 |
|
Line -... |
Line 17... |
- |
|
17 |
package net.brutex.xservices.ws.impl;
|
17 |
package net.brutex.xservices.ws.impl;
|
18 |
|
18 |
|
19 |
import lombok.extern.slf4j.Slf4j;
|
19 |
import net.brutex.xservices.types.*;
|
20 |
import net.brutex.xservices.types.*;
|
20 |
import net.brutex.xservices.types.alfevent.ALFEventResponseType;
|
21 |
import net.brutex.xservices.types.alfevent.ALFEventResponseType;
|
21 |
import net.brutex.xservices.types.alfevent.ALFEventType;
|
22 |
import net.brutex.xservices.types.alfevent.ALFEventType;
|
22 |
import net.brutex.xservices.types.alfevent.ObjectFactory;
|
23 |
import net.brutex.xservices.types.alfevent.ObjectFactory;
|
- |
|
24 |
import net.brutex.xservices.types.ant.FileSetResource;
|
23 |
import net.brutex.xservices.types.ant.FileSetResource;
|
25 |
import net.brutex.xservices.util.EventEmitter;
|
24 |
import net.brutex.xservices.util.EventEmitter;
|
26 |
import net.brutex.xservices.util.EventmanagerConfiguration;
|
25 |
import net.brutex.xservices.util.RunTask;
|
27 |
import net.brutex.xservices.util.RunTask;
|
26 |
import net.brutex.xservices.ws.MiscService;
|
28 |
import net.brutex.xservices.ws.MiscService;
|
27 |
import net.brutex.xservices.ws.XServicesFault;
|
29 |
import net.brutex.xservices.ws.XServicesFault;
|
Line 44... |
Line 46... |
44 |
import java.io.StringReader;
|
46 |
import java.io.StringReader;
|
45 |
import java.io.StringWriter;
|
47 |
import java.io.StringWriter;
|
46 |
import java.math.BigInteger;
|
48 |
import java.math.BigInteger;
|
47 |
import java.sql.*;
|
49 |
import java.sql.*;
|
48 |
import java.time.Instant;
|
50 |
import java.time.Instant;
|
49 |
import java.time.temporal.ChronoUnit;
|
- |
|
50 |
import java.util.Date;
|
51 |
import java.util.Date;
|
51 |
import java.util.Enumeration;
|
52 |
import java.util.Enumeration;
|
52 |
import java.util.Properties;
|
53 |
import java.util.Properties;
|
53 |
import java.util.UUID;
|
54 |
import java.util.UUID;
|
- |
|
55 |
import java.util.concurrent.atomic.AtomicLong;
|
Line 54... |
Line 56... |
54 |
|
56 |
|
Line 55... |
Line 57... |
55 |
import static org.quartz.TriggerBuilder.newTrigger;
|
57 |
import static org.quartz.TriggerBuilder.newTrigger;
|
56 |
|
58 |
|
57 |
|
59 |
|
58 |
/**
|
60 |
/**
|
59 |
* Implements the web service
|
61 |
* Implements the web service
|
- |
|
62 |
*
|
60 |
*
|
63 |
* @author Brian Rosenberger, bru@brutex.de
|
61 |
* @author Brian Rosenberger, bru@brutex.de
|
64 |
*/
|
62 |
*/
|
65 |
@Slf4j
|
Line 63... |
Line 66... |
63 |
@WebService(targetNamespace="http://ws.xservices.brutex.net", endpointInterface="net.brutex.xservices.ws.MiscService", serviceName="MiscService")
|
66 |
@WebService(targetNamespace="http://ws.xservices.brutex.net", endpointInterface="net.brutex.xservices.ws.MiscService", serviceName="MiscService")
|
64 |
public class MiscServiceImpl
|
67 |
public class MiscServiceImpl
|
65 |
implements MiscService {
|
- |
|
66 |
|
- |
|
67 |
@Resource
|
- |
|
68 |
private WebServiceContext context;
|
- |
|
69 |
|
- |
|
70 |
// Grab the Scheduler instance from the Factory
|
- |
|
71 |
private final Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
|
- |
|
72 |
private final static String conStr = "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=-1;";
|
- |
|
73 |
|
- |
|
74 |
private final static String dbinit = "" +
|
- |
|
75 |
"CREATE SCHEMA IF NOT EXISTS brutex;" +
|
- |
|
76 |
"CREATE TABLE IF NOT EXISTS brutex.tbl_events (" +
|
- |
|
77 |
"btx_event_type VARCHAR(128) NOT NULL," +
|
- |
|
78 |
"btx_id VARCHAR(32) NOT NULL, " +
|
- |
|
79 |
"btx_obj_type VARCHAR(32) NOT NULL, " +
|
- |
|
80 |
"btx_obj_id VARCHAR(32) NOT NULL, " +
|
- |
|
81 |
"btx_timestamp BIGINT NOT NULL," +
|
- |
|
82 |
"btx_event CLOB" +
|
- |
|
83 |
");" +
|
68 |
implements MiscService {
|
84 |
"CREATE INDEX IF NOT EXISTS brutex.btx_idx ON brutex.tbl_events (btx_obj_id, btx_obj_type, btx_event_type);" +
|
69 |
|
Line 85... |
Line 70... |
85 |
"CREATE INDEX IF NOT EXISTS brutex.IDX_TO_DESC ON brutex.tbl_events (btx_timestamp ASC);";
|
70 |
@Resource
|
86 |
|
71 |
private WebServiceContext context;
|
Line 239... |
Line 224... |
239 |
|
224 |
|
240 |
@Override
|
225 |
@Override
|
241 |
public ALFEventResponseType mergeALFEvent(ALFEventType event) throws XServicesFault {
|
226 |
public ALFEventResponseType mergeALFEvent(ALFEventType event) throws XServicesFault {
|
242 |
final Instant d = Instant.now();
|
227 |
final Instant d = Instant.now();
|
243 |
final long ts = d.toEpochMilli();
|
- |
|
Line -... |
Line 228... |
- |
|
228 |
final long ts = d.toEpochMilli();
|
244 |
//System.out.println("Step 1: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
229 |
|
245 |
|
230 |
//Get Parameters from the Servlet Context
|
- |
|
231 |
final ServletContext servletContext =
|
- |
|
232 |
(ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
|
- |
|
233 |
final EventmanagerConfiguration conf = (EventmanagerConfiguration) servletContext
|
246 |
final ServletContext servletContext =
|
234 |
.getAttribute(EventmanagerConfiguration.KEY);
|
- |
|
235 |
|
- |
|
236 |
final JdbcConnectionPool pool = (JdbcConnectionPool) servletContext.getAttribute("mdbConnection");
|
- |
|
237 |
final JdbcConnectionPool fpool = (JdbcConnectionPool) servletContext.getAttribute("fdbConnection");
|
- |
|
238 |
final AtomicLong egres_counter = (AtomicLong) servletContext.getAttribute("egres_counter");
|
- |
|
239 |
final AtomicLong ingres_counter = (AtomicLong) servletContext.getAttribute("ingres_counter");
|
- |
|
240 |
final Scheduler scheduler = (Scheduler) servletContext.getAttribute("scheduler");
|
- |
|
241 |
|
247 |
(ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
|
242 |
log.trace("Read dbConnection from servlet context: {}", pool);
|
248 |
final JdbcConnectionPool pool = (JdbcConnectionPool) servletContext.getAttribute("dbConnection");
|
243 |
|
Line 249... |
Line 244... |
249 |
//System.out.println("Step 2: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
244 |
//System.out.println("Step 2: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
250 |
final ObjectFactory of = new ObjectFactory();
|
245 |
final ObjectFactory of = new ObjectFactory();
|
251 |
|
246 |
|
252 |
final String objectId = event.getBase().getObjectId();
|
247 |
final String objectId = event.getBase().getObjectId();
|
- |
|
248 |
final String eventId = event.getBase().getEventId();
|
- |
|
249 |
final String objectType = event.getBase().getObjectType();
|
Line 253... |
Line 250... |
253 |
final String eventId = event.getBase().getEventId();
|
250 |
final String eventType = event.getBase().getEventType();
|
254 |
final String objectType = event.getBase().getObjectType();
|
251 |
log.debug("Event id '{}', type '{}' received for object '{}' with object_id '{}'.",
|
255 |
final String eventType = event.getBase().getEventType();
|
252 |
eventId, eventType, objectType, objectId);
|
256 |
|
253 |
|
Line 257... |
Line -... |
257 |
final String mergeStatememt = "MERGE INTO brutex.tbl_events " +
|
- |
|
258 |
"KEY (btx_event_type, btx_obj_type, btx_obj_id) " +
|
- |
|
259 |
"VALUES (?,?,?,?,?,?) " +
|
254 |
final String mergeStatememt = "MERGE INTO brutex.tbl_events " +
|
260 |
"";
|
- |
|
261 |
|
255 |
"KEY (btx_event_type, btx_obj_type, btx_obj_id) " +
|
262 |
long rows = 0L;
|
256 |
"VALUES (?,?,?,?,?,?);";
|
263 |
//System.out.println("Step 3: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
257 |
|
264 |
try {
|
258 |
|
265 |
//System.out.println("Step 4: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
259 |
try {
|
266 |
Marshaller m = JAXBContext.newInstance(ALFEventType.class).createMarshaller();
|
260 |
Marshaller m = JAXBContext.newInstance(ALFEventType.class).createMarshaller();
|
267 |
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
261 |
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
268 |
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
262 |
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
- |
|
263 |
JAXBElement<ALFEventType> e = of.createEventNotice(event);
|
269 |
JAXBElement<ALFEventType> e = of.createEventNotice(event);
|
264 |
StringWriter sw = new StringWriter();
|
270 |
StringWriter sw = new StringWriter();
|
265 |
m.marshal(e, sw);
|
271 |
m.marshal(e, sw);
|
266 |
StringBuilder sb = new StringBuilder();
|
272 |
StringBuilder sb = new StringBuilder();
|
267 |
sb.append(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
|
273 |
sb.append(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.eclipse.org/alf/schema/EventBase/1\">\n");
|
268 |
"xmlns:ns=\"http://www.eclipse.org/alf/schema/EventBase/1\">\n");
|
274 |
sb.append("<soapenv:Body>\n");
|
269 |
sb.append("<soapenv:Body>\n");
|
275 |
sb.append("<ns:EventNotice>\n");
|
- |
|
- |
|
270 |
sb.append("<ns:EventNotice>\n");
|
276 |
sb.append(sw);
|
271 |
sb.append(sw);
|
277 |
sb.append("</ns:EventNotice>\n");
|
- |
|
278 |
sb.append("</soapenv:Body>");
|
272 |
sb.append("</ns:EventNotice>\n");
|
279 |
sb.append("</soapenv:Envelope>");
|
273 |
sb.append("</soapenv:Body>");
|
280 |
//System.out.println("Step 5: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
274 |
sb.append("</soapenv:Envelope>");
|
281 |
Connection con = pool.getConnection();
|
275 |
|
282 |
//System.out.println("Step 6: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
276 |
Connection con = pool.getConnection();
|
283 |
PreparedStatement prep = con.prepareStatement(mergeStatememt);
|
277 |
PreparedStatement prep = con.prepareStatement(mergeStatememt);
|
284 |
prep.setString(1, eventType);
|
278 |
prep.setString(1, eventType);
|
285 |
prep.setString(2, eventId);
|
- |
|
286 |
prep.setString(3, objectType);
|
- |
|
287 |
prep.setString(4, objectId);
|
279 |
prep.setString(2, eventId);
|
288 |
prep.setLong(5, ts);
|
280 |
prep.setString(3, objectType);
|
289 |
prep.setClob(6, new StringReader(sb.toString()));
|
281 |
prep.setString(4, objectId);
|
290 |
//prep.setLong(7, ts-20000);
|
- |
|
291 |
//System.out.println("Step 7 SQL START: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
- |
|
292 |
prep.execute();
|
- |
|
Line -... |
Line 282... |
- |
|
282 |
prep.setLong(5, ts);
|
Line 293... |
Line -... |
293 |
con.commit();
|
- |
|
294 |
con.close();
|
- |
|
295 |
//System.out.println("Step 8 SQL END: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
- |
|
296 |
//SimpleSoap ss = new SimpleSoap("http://localhost:8099/ALFEventManager/services/ALFEventManagerSOAP", sb.toString());
|
- |
|
297 |
//ss.sendSoap(false);
|
- |
|
298 |
|
- |
|
299 |
|
- |
|
300 |
// and start it off
|
283 |
prep.setClob(6, new StringReader(sb.toString()));
|
301 |
|
284 |
prep.execute();
|
302 |
if (!scheduler.isStarted())
|
285 |
con.commit();
|
303 |
scheduler.start();
|
286 |
con.close();
|
- |
|
287 |
|
304 |
if (scheduler.isInStandbyMode())
|
288 |
ingres_counter.incrementAndGet();
|
305 |
scheduler.resumeAll();
|
289 |
|
306 |
//System.out.println("Step 9: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
290 |
synchronized (scheduler) {
|
- |
|
291 |
if (!scheduler.checkExists(JobKey.jobKey("ALFEmitter"))) {
|
- |
|
292 |
JobDetail job2 = JobBuilder.newJob(EventEmitter.class)
|
- |
|
293 |
.withIdentity("ALFEmitter")
|
- |
|
294 |
.build();
|
Line 307... |
Line 295... |
307 |
synchronized (scheduler) {
|
295 |
job2.getJobDataMap().put("mdbConnection", pool);
|
308 |
if (!scheduler.checkExists(JobKey.jobKey("ALFEmitter"))) {
|
296 |
job2.getJobDataMap().put("fdbConnection", fpool);
|
309 |
JobDetail job2 = JobBuilder.newJob(EventEmitter.class)
|
297 |
job2.getJobDataMap().put("run_key", ts);
|
Line 310... |
Line 298... |
310 |
.withIdentity("ALFEmitter").build();
|
298 |
job2.getJobDataMap().put("egres_counter", egres_counter);
|
311 |
//job2.getJobDataMap().put("script", job.getScript());
|
299 |
job2.getJobDataMap().put("ingres_counter", ingres_counter);
|
312 |
//job2.getJobDataMap().put("description", job.getDescription());
|
300 |
|
313 |
//job2.getJobDataMap().put("date", job.getDate());
|
- |
|
314 |
|
301 |
job2.getJobDataMap().put(EventmanagerConfiguration.KEY, conf);
|
- |
|
302 |
|
315 |
SimpleTrigger t = (SimpleTrigger) newTrigger()
|
303 |
SimpleTrigger t = (SimpleTrigger) newTrigger()
|
316 |
.withIdentity("ALFEmitter").startAt(Date.from(d.plusSeconds(20)))
|
304 |
.withIdentity("ALFEmitter").startAt(Date.from(d.plusSeconds(conf.getInterval())))
|
317 |
.build();
|
305 |
.build();
|
318 |
|
306 |
|
319 |
scheduler.scheduleJob(job2, t);
|
307 |
scheduler.scheduleJob(job2, t);
|
320 |
}
|
308 |
}
|