|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
MAXIMO RMI 伺服器, 可直接執行main程式, 但記憶體要加大, 如下:
-Xms512m -Xmx1024m -XX:MaxPermSize=128m
package xxx.server;
import java.io.InputStream;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.Properties;
import psdi.server.MXServer;
import psdi.server.MaxPropCache;
import psdi.server.MaximoThread;
import psdi.server.MaximoThreadGroup;
import psdi.util.IBMComInstanciator;
import psdi.util.MXProperties;
import psdi.util.logging.FixedLoggers;
import psdi.util.logging.MXLogger;
import psdi.util.logging.MXLoggerFactory;
public class LocalServer {
private static MXLogger logger = FixedLoggers.MAXIMOLOGGER;
public static void main(String[] args) {
LocalServer lSrv = new LocalServer();
try {
lSrv.init();
System.out.println("*server initialed*****");
MXLoggerFactory.applySettings(true);
System.in.read();
} catch (Throwable e) {
e.printStackTrace();
} finally {
System.out.println("*server destroy*****");
lSrv.destroy();
System.exit(0);
}
}
public void init() {
try {
//
InputStream in = getClass().getResourceAsStream("/maximo.properties");
Properties configProperties = MXProperties.loadProperties(in, true);
MXServer.start(configProperties);
MXServer mxSrv = MXServer.getMXServer();
//
MaxPropCache propCache = (MaxPropCache)mxSrv.getFromMaximoCache("MAXPROP");
Properties pops = propCache.getProperties();
//不檢查WebService存在
pops.setProperty("mxe.int.verifywebappurl", "false");
pops.setProperty("mxe.int.resolveschema", "1");
//
System.out.println("mxe.int.verifywebappurl="+mxSrv.getProperty("mxe.int.verifywebappurl"));
System.out.println("mxe.int.resolveschema="+mxSrv.getProperty("mxe.int.resolveschema"));
//
registerCOMDriver();
} catch (Exception ex) {
String msg;
if (logger.isErrorEnabled()) {
msg = "BMXAA6538E - Failed to initialize MAXIMO business object services.";
logger.error(msg, ex);
}
ex.printStackTrace();
}
}
public void destroy() {
try {
MXServer.getMXServer().destroy();
} catch (Throwable e) {
if (logger.isErrorEnabled()) {
String msg = "BMXAA6540E - Failed to cleanup MAXIMO business object services.";
logger.error(msg, e);
}
}
MaximoThreadGroup mt = MaximoThreadGroup.getMXThreadGroup();
int activeCount = mt.activeCount();
Thread mxThreads[] = new Thread[activeCount];
int noThreads = mt.enumerate(mxThreads);
for (int i = 0; i < noThreads; i++) {
MaximoThread x = (MaximoThread) mxThreads[i];
x.markShutdown();
x.interrupt();
}
try {
String url = MXServer.getMXServer().getURL();
if (url != null) {
Naming.unbind(url);
if (logger.isInfoEnabled()) {
String msg = (new StringBuilder()).append("BMXAA6541I - Unbound ").append(url).toString();
logger.info(msg);
}
}
} catch (Throwable ex) {
if (logger.isErrorEnabled()) {
String msg = "BMXAA6542E - Failed to unbind MAXIMO business services.";
logger.error(msg, ex);
}
}
}
public void registerCOMDriver() throws RemoteException {
String propval;
propval = MXServer.getMXServer().getConfig().getProperty("mxe.com.port");
if (propval == null)
return;
try {
System.out.println("COM Port:"+propval);
System.setProperty("JINTEGRA_DCOM_PORT", propval);
registerCom();
} catch (Exception e) {
if (logger.isErrorEnabled()) {
String msg = "BMXAA6543E - Failed register com driver.";
logger.error(msg, e);
}
}
return;
}
private void registerCom() throws Exception {
IBMComInstanciator oInstance = new psdi.util.IBMComInstanciator();
String svrName = MXServer.getMXServer().getName();
System.out.println("Server Name:"+svrName);
com.linar.jintegra.Jvm.register(svrName, oInstance);
System.out.println(com.linar.jintegra.Jvm.getMoniker());
logger.info("BMXAA6544I - registered the com driver");
}
}
唯 maximo.properties要放在路徑下, 就可直接執行, RMI伺服器, 透過JUnit,或遠端RMI連線即可測試MBO,範例如下:
MXSession session = MXSession.getSession();
session.setHost("localhost:13400/MXServer");
session.setUserName("wilson");
session.setPassword("wilson");
session.connect();
MboSetRemote mSet = session.getMboSet("SR");
.....
|
|