![JAR search and dependency download from the Maven repository](/logo.png)
org.jpos.q2.cli.deploy.SERVICE Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jpos Show documentation
Show all versions of jpos Show documentation
jPOS is an ISO-8583 based financial transaction
library/framework that can be customized and
extended in order to implement financial interchanges.
/*
* jPOS Project [http://jpos.org]
* Copyright (C) 2000-2018 jPOS Software SRL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package org.jpos.q2.cli.deploy;
import java.util.Iterator;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;
import org.jpos.q2.Q2;
import org.jpos.q2.QBean;
/**
* CLI implementation - Deploy subsystem
*
* @author Felipph Calado - [email protected]
*/
public class SERVICE implements CLICommand {
@Override
public void exec(CLIContext ctx, String[] args) throws Exception {
if (args.length < 3) {
ctx.println("Usage: service start|stop|restart");
return;
}
if (!"start".equals(args[2]) && !"stop".equals(args[2]) && !"restart".equals(args[2])) {
ctx.println("Invalid operation: " + args[2]);
return;
}
String command = "";
int waiting = 0;
int executed = 0;
switch (args[2]) {
case "start":
command = "start";
waiting = QBean.STARTING;
executed = QBean.STARTED;
break;
case "stop":
command = "stop";
waiting = QBean.STOPPING;
executed = QBean.STOPPED;
break;
case "restart":
args[2] = "stop";
this.exec(ctx, args);
args[2] = "start";
this.exec(ctx, args);
return;
}
MBeanServer server = ctx.getCLI().getQ2().getMBeanServer();
ObjectName on = new ObjectName(Q2.QBEAN_NAME + args[1]);
Set b = server.queryMBeans(on, null);
Iterator it = b.iterator();
if (it.hasNext()) {
ObjectInstance instance = it.next();
if ((Integer) server.getAttribute(instance.getObjectName(), "State") == executed) {
ctx.println(args[2] + ": " + args[1] + " already done.");
return;
}
server.invoke(instance.getObjectName(), command, null, null);
try {
for (int i = 0; i < 100; i++) {
if ((Integer) server.getAttribute(instance.getObjectName(), "State") == executed) {
ctx.println(args[2] + ": " + args[1] + " done");
return;
}
Thread.sleep(2000);// wait to stop...
ctx.println("waiting for " + args[1] + " to " + args[2]);
}
ctx.println(args[2] + ": " + args[1] + " is stuck in " + waiting + " state");
return;
} catch (Exception e) {
ctx.println("Can't get state: " + args[1]);
}
return;
} else {
ctx.println(args[1] + " not found");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy