Subversion Repositories XServices

Rev

Rev 199 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 199 Rev 201
1
/*
1
/*
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
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;
23
import net.brutex.xservices.types.ant.FileSetResource;
24
import net.brutex.xservices.types.ant.FileSetResource;
24
import net.brutex.xservices.util.EventEmitter;
25
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;
28
import org.apache.tools.ant.taskdefs.HostInfo;
30
import org.apache.tools.ant.taskdefs.HostInfo;
29
import org.apache.tools.ant.taskdefs.Sleep;
31
import org.apache.tools.ant.taskdefs.Sleep;
30
import org.apache.tools.ant.taskdefs.email.EmailTask;
32
import org.apache.tools.ant.taskdefs.email.EmailTask;
31
import org.h2.jdbcx.JdbcConnectionPool;
33
import org.h2.jdbcx.JdbcConnectionPool;
32
import org.quartz.*;
34
import org.quartz.*;
33
import org.quartz.impl.StdSchedulerFactory;
35
import org.quartz.impl.StdSchedulerFactory;
34
 
36
 
35
import javax.annotation.Resource;
37
import javax.annotation.Resource;
36
import javax.jws.WebService;
38
import javax.jws.WebService;
37
import javax.servlet.ServletContext;
39
import javax.servlet.ServletContext;
38
import javax.xml.bind.JAXBContext;
40
import javax.xml.bind.JAXBContext;
39
import javax.xml.bind.JAXBElement;
41
import javax.xml.bind.JAXBElement;
40
import javax.xml.bind.JAXBException;
42
import javax.xml.bind.JAXBException;
41
import javax.xml.bind.Marshaller;
43
import javax.xml.bind.Marshaller;
42
import javax.xml.ws.WebServiceContext;
44
import javax.xml.ws.WebServiceContext;
43
import javax.xml.ws.handler.MessageContext;
45
import javax.xml.ws.handler.MessageContext;
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;
54
 
56
 
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
60
 * 
62
 * 
61
 * @author Brian Rosenberger, bru@brutex.de
63
 * @author Brian Rosenberger, bru@brutex.de
62
 */
64
 */
-
 
65
@Slf4j
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 {
68
  implements MiscService {
66
 
69
 
67
  @Resource
70
  @Resource
68
  private WebServiceContext context;
71
  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
          ");" +
-
 
84
          "CREATE INDEX IF NOT EXISTS brutex.btx_idx ON brutex.tbl_events (btx_obj_id, btx_obj_type, btx_event_type);" +
-
 
85
          "CREATE INDEX IF NOT EXISTS brutex.IDX_TO_DESC ON brutex.tbl_events (btx_timestamp ASC);";
-
 
86
 
-
 
87
    public MiscServiceImpl() throws SchedulerException {
72
    public MiscServiceImpl() throws SchedulerException {
88
    }
73
    }
89
 
74
 
90
    public HostinfoType getHostinfo(String hostname) {
75
    public HostinfoType getHostinfo(String hostname) {
91
    HostInfo info = new HostInfo();
76
    HostInfo info = new HostInfo();
92
    info.setTaskName("HostInfo");
77
    info.setTaskName("HostInfo");
93
    RunTask runner = new RunTask(info);
78
    RunTask runner = new RunTask(info);
94
    info.setHost(hostname);
79
    info.setHost(hostname);
95
 
80
 
96
    ReturnCode ret = runner.postTask();
81
    ReturnCode ret = runner.postTask();
97
    HostinfoType infotype = new HostinfoType(
82
    HostinfoType infotype = new HostinfoType(
98
            ret.getProperty("NAME"),
83
            ret.getProperty("NAME"),
99
            ret.getProperty("DOMAIN"),
84
            ret.getProperty("DOMAIN"),
100
            ret.getProperty("ADDR4"),
85
            ret.getProperty("ADDR4"),
101
            ret.getProperty("ADDR6"));
86
            ret.getProperty("ADDR6"));
102
    return infotype;
87
    return infotype;
103
  }
88
  }
104
 
89
 
105
  public ReturnCode getInfo() {
90
  public ReturnCode getInfo() {
106
    ReturnCode r = new ReturnCode();
91
    ReturnCode r = new ReturnCode();
107
    r.returnCode = 0;
92
    r.returnCode = 0;
108
 
93
 
109
    Properties props = System.getProperties();
94
    Properties props = System.getProperties();
110
 
95
 
111
    Enumeration e = props.propertyNames();
96
    Enumeration e = props.propertyNames();
112
    while (e.hasMoreElements()) {
97
    while (e.hasMoreElements()) {
113
      String propName = (String) e.nextElement();
98
      String propName = (String) e.nextElement();
114
 
99
 
115
      String propValue = (String) props.get(propName);
100
      String propValue = (String) props.get(propName);
116
      r.stdOut = (r.stdOut + propName + ": " + propValue + "\n");
101
      r.stdOut = (r.stdOut + propName + ": " + propValue + "\n");
117
    }
102
    }
118
 
103
 
119
    return r;
104
    return r;
120
  }
105
  }
121
 
106
 
122
  public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) {
107
  public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) {
123
    return sendMail(from, from, tolist, "", "", subject, message,
108
    return sendMail(from, from, tolist, "", "", subject, message,
124
            "text/plain", null, mailhost.hostname, mailhost.port,
109
            "text/plain", null, mailhost.hostname, mailhost.port,
125
            mailhost.user, mailhost.password, "utf-8", false, false);
110
            mailhost.user, mailhost.password, "utf-8", false, false);
126
  }
111
  }
127
 
112
 
128
  public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from, String tolist, String subject, String message, FileSetResource res) {
113
  public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from, String tolist, String subject, String message, FileSetResource res) {
129
    return sendMail(from, from, tolist, "", "", subject, message,
114
    return sendMail(from, from, tolist, "", "", subject, message,
130
            "text/plain", res, mailhost.hostname, mailhost.port,
115
            "text/plain", res, mailhost.hostname, mailhost.port,
131
            mailhost.user, mailhost.password, "utf-8", false, false);
116
            mailhost.user, mailhost.password, "utf-8", false, false);
132
  }
117
  }
133
 
118
 
134
  public ReturnCode sendMail(HostConnection mailhost, String from, String tolist, String cclist, String bcclist, String subject, MailMimeType mimetype, String charset, String message, FileSetResource res, boolean ssl, boolean tls) {
119
  public ReturnCode sendMail(HostConnection mailhost, String from, String tolist, String cclist, String bcclist, String subject, MailMimeType mimetype, String charset, String message, FileSetResource res, boolean ssl, boolean tls) {
135
    return sendMail(from, from, tolist, cclist, bcclist, subject, message,
120
    return sendMail(from, from, tolist, cclist, bcclist, subject, message,
136
            mimetype.value(), res, mailhost.hostname, mailhost.port,
121
            mimetype.value(), res, mailhost.hostname, mailhost.port,
137
            mailhost.user, mailhost.password, charset, tls, ssl);
122
            mailhost.user, mailhost.password, charset, tls, ssl);
138
  }
123
  }
139
 
124
 
140
  public ReturnCode sleep(int minutes, int seconds) {
125
  public ReturnCode sleep(int minutes, int seconds) {
141
    return sleep(0, minutes, seconds, 0);
126
    return sleep(0, minutes, seconds, 0);
142
  }
127
  }
143
 
128
 
144
  public String generateUUID() {
129
  public String generateUUID() {
145
    return UUID.randomUUID().toString();
130
    return UUID.randomUUID().toString();
146
  }
131
  }
147
 
132
 
148
  private ReturnCode sendMail(String from, String replyto, String tolist, String cclist, String bcclist, String subject, String message, String messagemimetype, FileSetResource attachments, String mailhost, int mailport, String user, String password, String charset, boolean tls, boolean ssl) {
133
  private ReturnCode sendMail(String from, String replyto, String tolist, String cclist, String bcclist, String subject, String message, String messagemimetype, FileSetResource attachments, String mailhost, int mailport, String user, String password, String charset, boolean tls, boolean ssl) {
149
    EmailTask mail = new EmailTask();
134
    EmailTask mail = new EmailTask();
150
    mail.setTaskName("Mail");
135
    mail.setTaskName("Mail");
151
    RunTask runner = new RunTask(mail);
136
    RunTask runner = new RunTask(mail);
152
    mail.setFrom(from);
137
    mail.setFrom(from);
153
    mail.setReplyTo(replyto);
138
    mail.setReplyTo(replyto);
154
    mail.setToList(tolist);
139
    mail.setToList(tolist);
155
    mail.setCcList(cclist);
140
    mail.setCcList(cclist);
156
    mail.setBccList(bcclist);
141
    mail.setBccList(bcclist);
157
    mail.setSubject(subject);
142
    mail.setSubject(subject);
158
    mail.setMessage(message);
143
    mail.setMessage(message);
159
    mail.setMessageMimeType(messagemimetype);
144
    mail.setMessageMimeType(messagemimetype);
160
    if (attachments != null) {
145
    if (attachments != null) {
161
      mail.addFileset(attachments.getAntResource(mail.getProject()));
146
      mail.addFileset(attachments.getAntResource(mail.getProject()));
162
    }
147
    }
163
    mail.setMailhost(mailhost);
148
    mail.setMailhost(mailhost);
164
    mail.setMailport(mailport);
149
    mail.setMailport(mailport);
165
    mail.setUser(user);
150
    mail.setUser(user);
166
    mail.setPassword(password);
151
    mail.setPassword(password);
167
    mail.setCharset(charset);
152
    mail.setCharset(charset);
168
    mail.setSSL(ssl);
153
    mail.setSSL(ssl);
169
    mail.setEnableStartTLS(tls);
154
    mail.setEnableStartTLS(tls);
170
    return runner.postTask();
155
    return runner.postTask();
171
  }
156
  }
172
 
157
 
173
  private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds) {
158
  private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds) {
174
    Sleep sleep = new Sleep();
159
    Sleep sleep = new Sleep();
175
    sleep.setTaskName("Sleep");
160
    sleep.setTaskName("Sleep");
176
    RunTask runner = new RunTask(sleep);
161
    RunTask runner = new RunTask(sleep);
177
    sleep.setHours(hours);
162
    sleep.setHours(hours);
178
    sleep.setMinutes(minutes);
163
    sleep.setMinutes(minutes);
179
    sleep.setSeconds(seconds);
164
    sleep.setSeconds(seconds);
180
    sleep.setMilliseconds(milliseconds);
165
    sleep.setMilliseconds(milliseconds);
181
    return runner.postTask();
166
    return runner.postTask();
182
  }
167
  }
183
 
168
 
184
  public RuntimeInfoType getMemory() {
169
  public RuntimeInfoType getMemory() {
185
    return new RuntimeInfoType();
170
    return new RuntimeInfoType();
186
  }
171
  }
187
 
172
 
188
  @Override
173
  @Override
189
  public BigInteger lock(String id, String objectId) throws XServicesFault {
174
  public BigInteger lock(String id, String objectId) throws XServicesFault {
190
 
175
 
191
 
176
 
192
 
177
 
193
    final String conString = "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=10;" +
178
    final String conString = "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=10;" +
194
            "INIT=CREATE SCHEMA IF NOT EXISTS brutex\\;" +
179
            "INIT=CREATE SCHEMA IF NOT EXISTS brutex\\;" +
195
            // "SET SCHEMA brutex\\;" +
180
            // "SET SCHEMA brutex\\;" +
196
            "CREATE SEQUENCE IF NOT EXISTS brutex.btx_sequence1\\;" +
181
            "CREATE SEQUENCE IF NOT EXISTS brutex.btx_sequence1\\;" +
197
            "CREATE TABLE IF NOT EXISTS brutex.tbl_lock (btx_seq BIGINT NOT NULL, btx_id VARCHAR(100) NOT NULL, btx_obj_id VARCHAR(100) NOT NULL, btx_timestamp BIGINT NOT NULL);";
182
            "CREATE TABLE IF NOT EXISTS brutex.tbl_lock (btx_seq BIGINT NOT NULL, btx_id VARCHAR(100) NOT NULL, btx_obj_id VARCHAR(100) NOT NULL, btx_timestamp BIGINT NOT NULL);";
198
 
183
 
199
    //JdbcConnectionPool cp = JdbcConnectionPool.create(conString, "sa", "");
184
    //JdbcConnectionPool cp = JdbcConnectionPool.create(conString, "sa", "");
200
    //cp.setMaxConnections(1);
185
    //cp.setMaxConnections(1);
201
 
186
 
202
    Connection con = null;
187
    Connection con = null;
203
    long rows = 0L;
188
    long rows = 0L;
204
    final long ts = new Date().getTime();
189
    final long ts = new Date().getTime();
205
    try {
190
    try {
206
      Class.forName("org.h2.Driver"); //Java 1.8
191
      Class.forName("org.h2.Driver"); //Java 1.8
207
      con = DriverManager.getConnection(conString);
192
      con = DriverManager.getConnection(conString);
208
      PreparedStatement prep = con.prepareStatement(
193
      PreparedStatement prep = con.prepareStatement(
209
              "SELECT btx_id from brutex.tbl_lock where btx_obj_id=? ORDER BY btx_seq DESC");
194
              "SELECT btx_id from brutex.tbl_lock where btx_obj_id=? ORDER BY btx_seq DESC");
210
      prep.setString(1, objectId);
195
      prep.setString(1, objectId);
211
 
196
 
212
      ResultSet rs = prep.executeQuery();
197
      ResultSet rs = prep.executeQuery();
213
      StringBuffer bf = new StringBuffer();
198
      StringBuffer bf = new StringBuffer();
214
      while (rs.next()) {
199
      while (rs.next()) {
215
        //bf.append(rs.getString(1));
200
        //bf.append(rs.getString(1));
216
        rows++;
201
        rows++;
217
      }
202
      }
218
      rs.close();
203
      rs.close();
219
 
204
 
220
      prep = con.prepareStatement("INSERT INTO brutex.tbl_lock values (NEXT VALUE FOR brutex.btx_sequence1, ?, ?, ?)");
205
      prep = con.prepareStatement("INSERT INTO brutex.tbl_lock values (NEXT VALUE FOR brutex.btx_sequence1, ?, ?, ?)");
221
      prep.setString(1, id);
206
      prep.setString(1, id);
222
      prep.setString(2, objectId);
207
      prep.setString(2, objectId);
223
      prep.setLong(3, ts);
208
      prep.setLong(3, ts);
224
      prep.execute();
209
      prep.execute();
225
 
210
 
226
      prep = con.prepareStatement("DELETE from brutex.tbl_lock WHERE btx_timestamp < ?");
211
      prep = con.prepareStatement("DELETE from brutex.tbl_lock WHERE btx_timestamp < ?");
227
      prep.setLong(1, ts - 10000);
212
      prep.setLong(1, ts - 10000);
228
      prep.execute();
213
      prep.execute();
229
      prep.close();
214
      prep.close();
230
 
215
 
231
      con.close();
216
      con.close();
232
      //System.out.println(bf);
217
      //System.out.println(bf);
233
    } catch (SQLException | ClassNotFoundException e) {
218
    } catch (SQLException | ClassNotFoundException e) {
234
      throw new XServicesFault(e);
219
      throw new XServicesFault(e);
235
    }
220
    }
236
 
221
 
237
    return BigInteger.valueOf(rows);
222
    return BigInteger.valueOf(rows);
238
  }
223
  }
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();
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
246
    final ServletContext servletContext =
231
    final ServletContext servletContext =
-
 
232
            (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
-
 
233
    final EventmanagerConfiguration conf = (EventmanagerConfiguration) servletContext
-
 
234
            .getAttribute(EventmanagerConfiguration.KEY);
247
            (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
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
 
-
 
242
    log.trace("Read dbConnection from servlet context: {}", pool);
248
    final JdbcConnectionPool pool = (JdbcConnectionPool) servletContext.getAttribute("dbConnection");
243
 
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();
253
    final String eventId = event.getBase().getEventId();
248
    final String eventId = event.getBase().getEventId();
254
    final String objectType = event.getBase().getObjectType();
249
    final String objectType = event.getBase().getObjectType();
255
    final String eventType = event.getBase().getEventType();
250
    final String eventType = event.getBase().getEventType();
-
 
251
    log.debug("Event id '{}', type '{}' received for object '{}' with object_id '{}'.",
-
 
252
            eventId, eventType, objectType, objectId);
256
 
253
 
257
    final String mergeStatememt = "MERGE INTO brutex.tbl_events " +
254
    final String mergeStatememt = "MERGE INTO brutex.tbl_events " +
258
            "KEY (btx_event_type, btx_obj_type, btx_obj_id) " +
255
            "KEY (btx_event_type, btx_obj_type, btx_obj_id) " +
259
            "VALUES (?,?,?,?,?,?) " +
256
            "VALUES (?,?,?,?,?,?);";
260
            "";
257
 
261
 
-
 
262
    long rows = 0L;
-
 
263
    //System.out.println("Step 3: " + ChronoUnit.MILLIS.between(Instant.now(), d));
258
 
264
    try {
-
 
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);
269
      JAXBElement<ALFEventType> e = of.createEventNotice(event);
263
      JAXBElement<ALFEventType> e = of.createEventNotice(event);
270
      StringWriter sw = new StringWriter();
264
      StringWriter sw = new StringWriter();
271
      m.marshal(e, sw);
265
      m.marshal(e, sw);
272
      StringBuilder sb = new StringBuilder();
266
      StringBuilder sb = new StringBuilder();
273
      sb.append(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.eclipse.org/alf/schema/EventBase/1\">\n");
267
      sb.append(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
-
 
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");
272
      sb.append("</ns:EventNotice>\n");
278
      sb.append("</soapenv:Body>");
273
      sb.append("</soapenv:Body>");
279
      sb.append("</soapenv:Envelope>");
274
      sb.append("</soapenv:Envelope>");
280
      //System.out.println("Step 5: " + ChronoUnit.MILLIS.between(Instant.now(), d));
-
 
-
 
275
 
281
      Connection con = pool.getConnection();
276
      Connection con = pool.getConnection();
282
      //System.out.println("Step 6: " + ChronoUnit.MILLIS.between(Instant.now(), d));
-
 
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);
279
      prep.setString(2, eventId);
286
      prep.setString(3, objectType);
280
      prep.setString(3, objectType);
287
      prep.setString(4, objectId);
281
      prep.setString(4, objectId);
288
      prep.setLong(5, ts);
282
      prep.setLong(5, ts);
289
      prep.setClob(6, new StringReader(sb.toString()));
283
      prep.setClob(6, new StringReader(sb.toString()));
290
      //prep.setLong(7, ts-20000);
-
 
291
      //System.out.println("Step 7 SQL START: " + ChronoUnit.MILLIS.between(Instant.now(), d));
-
 
292
      prep.execute();
284
      prep.execute();
293
      con.commit();
285
      con.commit();
294
      con.close();
286
      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);
-
 
-
 
287
 
298
 
-
 
299
 
-
 
300
      // and start it off
-
 
301
 
-
 
302
      if (!scheduler.isStarted())
-
 
303
        scheduler.start();
-
 
304
      if (scheduler.isInStandbyMode())
-
 
305
        scheduler.resumeAll();
288
      ingres_counter.incrementAndGet();
306
      //System.out.println("Step 9: " + ChronoUnit.MILLIS.between(Instant.now(), d));
289
 
307
      synchronized (scheduler) {
290
      synchronized (scheduler) {
308
          if (!scheduler.checkExists(JobKey.jobKey("ALFEmitter"))) {
291
          if (!scheduler.checkExists(JobKey.jobKey("ALFEmitter"))) {
309
            JobDetail job2 = JobBuilder.newJob(EventEmitter.class)
292
            JobDetail job2 = JobBuilder.newJob(EventEmitter.class)
310
                    .withIdentity("ALFEmitter").build();
293
                    .withIdentity("ALFEmitter")
-
 
294
                    .build();
311
            //job2.getJobDataMap().put("script", job.getScript());
295
            job2.getJobDataMap().put("mdbConnection", pool);
312
            //job2.getJobDataMap().put("description", job.getDescription());
296
            job2.getJobDataMap().put("fdbConnection", fpool);
313
            //job2.getJobDataMap().put("date", job.getDate());
297
            job2.getJobDataMap().put("run_key", ts);
-
 
298
            job2.getJobDataMap().put("egres_counter", egres_counter);
-
 
299
            job2.getJobDataMap().put("ingres_counter", ingres_counter);
-
 
300
 
-
 
301
            job2.getJobDataMap().put(EventmanagerConfiguration.KEY, conf);
314
 
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
          }
321
      }
309
      }
322
      //System.out.println("Step 10: " + ChronoUnit.MILLIS.between(Instant.now(), d));
-
 
323
    } catch (JAXBException | SQLException | SchedulerException e) {
310
    } catch (JAXBException | SQLException | SchedulerException e) {
-
 
311
        log.error(e.getMessage());
324
      throw new XServicesFault(e);
312
        throw new XServicesFault(e);
325
    }
313
    }
326
    return of.createALFEventResponseType();
314
    return of.createALFEventResponseType();
327
  }
315
  }
328
}
316
}
329
 
317
 
330
Generated by GNU Enscript 1.6.5.90.
318
Generated by GNU Enscript 1.6.5.90.
331
 
319
 
332
 
320