


「印象.左岸–奧塞美術館30周年大展」 - 梵谷《午睡》

基隆港

- IS package class loaders 順序是下圖的 1.1 ~ 1.4
- 在 runtime 的時候,順序是下圖的 2.1 ~ 2.3
- 要注意的是,若有一個檔案同時存在於 jars 與 classes 的 folder,位於 jars folder 內的檔案擁有優先權
public static void logger(String message) { IData input = IDataFactory.create(); IDataCursor inputCursor = input.getCursor(); IDataUtil.put(inputCursor, "message", message); IDataUtil.put(inputCursor, "function", "customLogger"); IDataUtil.put(inputCursor, "level", "INFO"); inputCursor.destroy(); try { Service.doInvoke("pub.flow", "debugLog", input); } catch (Exception e) { e.printStackTrace(); } }
public static void loggerAsync(Session session, String message) { IData input = IDataFactory.create(); IDataCursor inputCursor = input.getCursor(); IDataUtil.put(inputCursor, "message", message); IDataUtil.put(inputCursor, "function", "customLogger"); IDataUtil.put(inputCursor, "level", "INFO"); inputCursor.destroy(); try { Service.doThreadInvoke("pub.flow", "debugLog", session, input); } catch (Exception e) { e.printStackTrace(); } }
// 非同步作業的呼叫方式 Session session = Service.getSession(); loggerAsync(session, "Hello~ asynch log"); // 同步作業的呼叫方式 logger("Hello~ log");
public final class Test_SVC { /** * The primary method for the Java service * * @param pipeline * The IData pipeline * @throws ServiceException */ public static final void Test(IData pipeline) throws ServiceException { IDataCursor pipelineCursor = pipeline.getCursor(); // Invoke the pub.date:getCurrentDateString service to get current date time String currentDateString = ""; IDataUtil.put(pipelineCursor, "pattern", "yyyy/MM/dd HH:mm:ss"); try { IData data = Service.doInvoke("pub.date", "getCurrentDateString", pipeline); currentDateString = (String) IDataUtil.get(data.getCursor(), "value"); } catch (Exception e) { throw new ServiceException(e); } // input name String name = IDataUtil.getString(pipelineCursor, "name"); IDataUtil.put(pipelineCursor, "name", name); // get current date time via pub.date:getCurrentDateString service IDataUtil.put(pipelineCursor, "dateTime", currentDateString); // Invoke HelloWorld service try { Service.doInvoke("acme.albert.work", "HelloWorld", pipeline); } catch (Exception e) { throw new ServiceException(e); } pipelineCursor.destroy(); } }
public final class HelloWorld_SVC { /** * The primary method for the Java service * * @param pipeline * The IData pipeline * @throws ServiceException */ public static final void HelloWorld(IData pipeline) throws ServiceException { // pipeline IDataCursor pipelineCursor = pipeline.getCursor(); String name = IDataUtil.getString(pipelineCursor, "name"); String dateTime = IDataUtil.getString(pipelineCursor, "dateTime"); logger("dateTime = " + dateTime); pipelineCursor.destroy(); // pipeline IDataCursor pipelineCursor_1 = pipeline.getCursor(); String welcomeMsg = "Hello~" + name + " (" + dateTime + ")"; logger("welcome msg = " + welcomeMsg); IDataUtil.put( pipelineCursor_1, "welcomeMessage", welcomeMsg ); pipelineCursor_1.destroy(); } // --- <<IS-BEGIN-SHARED-SOURCE-AREA>> --- public static void logger(String message) throws ServiceException { IData input = IDataFactory.create(); IDataCursor inputCursor = input.getCursor(); IDataUtil.put(inputCursor, "message", message); IDataUtil.put(inputCursor, "function", "customLogger"); IDataUtil.put(inputCursor, "level", "INFO"); inputCursor.destroy(); try { Service.doInvoke("pub.flow", "debugLog", input); } catch (Exception e) { throw new ServiceException(e); } } // --- <<IS-END-SHARED-SOURCE-AREA>> --- }
[9987]2016-11-16 15:52:31 TST [ISP.0090.0004I] customLogger -- welcome msg = Hello~Albert (2016/11/16 15:52:31) [9986]2016-11-16 15:52:31 TST [ISP.0090.0004I] customLogger -- dateTime = 2016/11/16 15:52:31
Session session = Service.getSession(); IData input = IDataFactory.create(); IDataCursor inputCursor = input.getCursor(); IDataUtil.put(inputCursor, "input", "hello"); inputCursor.destroy(); Service.doThreadInvoke("acme.albert.work.OPC", "OPC_Heartbeat_Flow", session, input);
import java.io.Serializable; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class OpcHeartbeatService { private final static Logger logger = LoggerFactory.getLogger(OpcHeartbeatService.class); public static void main(String[] args) { OpcHeartbeatService test = new OpcHeartbeatService(); logger.info("buildTestJson = " + test.buildTestJson()); } public String buildTestJson() { HBMessage hb_msg = new HBMessage("test", "123445", "HBT_MSG"); return buildHeartbeatMsgJson(hb_msg); } public String buildHeartbeatMsgJson(HBMessage hb_msg) { JSONObject dataset = new JSONObject(); JSONObject hbObject = new JSONObject(); hbObject.put("serviceId", hb_msg.getServiceId()); hbObject.put("token", hb_msg.getToken()); hbObject.put("type", hb_msg.getType()); dataset.accumulate("heartbeatMsg", hbObject); return dataset.toString(); } public static class HBMessage implements Serializable{ private static final long serialVersionUID = 1L; private String serviceId; private String token; private String type; public HBMessage() { super(); } public HBMessage(String serviceId, String token, String type) { super(); this.serviceId = serviceId; this.token = token; this.type = type; } public String getServiceId() { return serviceId; } public void setServiceId(String serviceId) { this.serviceId = serviceId; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public String getType() { return type; } public void setType(String type) { this.type = type; } @Override public String toString() { return "HBMessage [serviceId=" + serviceId + ", token=" + token + ", type=" + type + "]"; } } }
public final class OPC_Heartbeat_SVC { /** * The primary method for the Java service * * @param pipeline * The IData pipeline * @throws ServiceException */ public static final void OPC_Heartbeat(IData pipeline) throws ServiceException { OpcHeartbeatService hbService = new OpcHeartbeatService(); String hbJson = hbService.buildTestJson(); IDataCursor pipelineCursor = pipeline.getCursor(); IDataUtil.put(pipelineCursor, "heartbeatJson", hbJson); pipelineCursor.destroy(); } // ignore...... }