Example usage for java.rmi ConnectException getCause

List of usage examples for java.rmi ConnectException getCause

Introduction

In this page you can find the example usage for java.rmi ConnectException getCause.

Prototype

public Throwable getCause() 

Source Link

Document

Returns the cause of this exception.

Usage

From source file:org.openspaces.pu.container.servicegrid.deploy.Undeploy.java

public void undeploy(String[] args) throws Exception {
    if (args.length == 0) {
        throw new IllegalArgumentException("The pu name must be defined");
    }/*from ww w .j a  v a2  s .  c  o m*/
    String puPath = args[args.length - 1];
    int index = puPath.lastIndexOf('/');
    index = index == -1 ? 0 : index;
    String puName = puPath.substring(index);

    CommandLineParser.Parameter[] params = CommandLineParser.parse(args, args.length - 1);

    // check if we have a groups parameter and timeout parameter
    for (CommandLineParser.Parameter param : params) {
        if (param.getName().equalsIgnoreCase("groups")) {
            setGroups(param.getArguments());
        }
        if (param.getName().equalsIgnoreCase("locators")) {
            StringBuilder sb = new StringBuilder();
            for (String arg : param.getArguments()) {
                sb.append(arg).append(',');
            }
            setLocators(sb.toString());
        }
        if (param.getName().equalsIgnoreCase("timeout")) {
            setLookupTimeout(Integer.valueOf(param.getArguments()[0]));
        }
    }

    GSM[] gsms = findGSMs();
    if (gsms == null || gsms.length == 0) {
        throw new GSMNotFoundException(getGroups(), lookupTimeout);
    }
    //try undeploying using name first
    OperationalStringManager operationalStringManager = findDeployAdmin(gsms, puName);
    if (operationalStringManager != null) {
        try {
            operationalStringManager.undeploy();
        } catch (ConnectException e) {
            if (e.getCause() instanceof ClosedChannelException) {
                // all is well. When we destroy a service, we get a closed channel exception
                // since we closed the channel it is working on
            } else {
                throw e;
            }
        }
    } else {
        throw new ProcessingUnitNotFoundException(puName, gsms[0]);
    }
}