Example usage for org.apache.commons.lang3 SerializationUtils clone

List of usage examples for org.apache.commons.lang3 SerializationUtils clone

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SerializationUtils clone.

Prototype

public static <T extends Serializable> T clone(final T object) 

Source Link

Document

Deep clone an Object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph.

Usage

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Allows to start/create a ZigBee network using the
 * {@code StartupAttributeInfo} class as a previously configured parameter.
 * // ww w  .  j  a va 2s . c o  m
 * @param timeout
 *            the desired timeout
 * @param _requestIdentifier
 *            the request identifier
 * @param sai
 *            the {@code StartupAttributeInfo}
 * @param Async
 *            whether the operation will be asynchronous ({@code true}) or
 *            not ({@code false}).
 * @return the resulting status from ZGD.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */

public Status startGatewayDevice(final long timeout, final int _requestIdentifier,
        final StartupAttributeInfo sai, final boolean Async) throws IOException, Exception, GatewayException {
    // The network can start only from those two gateway status...
    if (Async) {
        executor.execute(new Runnable() {
            public void run() {

                if (getGatewayStatus() == GatewayStatus.GW_READY_TO_START
                        || getGatewayStatus() == GatewayStatus.GW_STOPPED) {

                    setGatewayStatus(GatewayStatus.GW_STARTING);
                    try {
                        Status _res = DataLayer.startGatewayDeviceSync(timeout, sai);
                        if (_res.getCode() == GatewayConstants.SUCCESS) {
                            LOG.debug("WriteSas completed!");
                            _lockerStartDevice.setId(0);
                            _lockerStartDevice.getObjectLocker().poll(timeout, TimeUnit.MILLISECONDS);
                            if (_lockerStartDevice.getId() > 0) {
                                lastSai = sai;
                                LOG.info("Gateway Started now!");

                            } else {
                                setGatewayStatus(GatewayStatus.GW_READY_TO_START);

                                LOG.error("*******Gateway NOT Started!");
                                _res.setCode((short) GatewayConstants.GENERAL_ERROR);
                                _res.setMessage("No Network Event Running received!");

                            }
                        } else {
                            LOG.error("*******Gateway NOT Started!");
                        }

                        get_gatewayEventManager().notifyGatewayStartResult(_res);
                    } catch (IOException e) {
                        Status _s = new Status();
                        _s.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s.setMessage(e.getMessage());
                        get_gatewayEventManager().notifyGatewayStartResult(_requestIdentifier, _s);

                    } catch (GatewayException e) {
                        Status _s = new Status();
                        _s.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s.setMessage(e.getMessage());

                        get_gatewayEventManager().notifyGatewayStartResult(_requestIdentifier, _s);

                    } catch (Exception e) {
                        Status _s = new Status();
                        _s.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s.setMessage(e.getMessage());

                        get_gatewayEventManager().notifyGatewayStartResult(_requestIdentifier, _s);

                    }
                } else {
                    // ...from all others, throw an exception
                    String message = "Trying to start Gateway Device in " + getGatewayStatus() + " state.";
                    LOG.debug(message);
                    Status _s = new Status();
                    _s.setCode((short) GatewayConstants.GENERAL_ERROR);
                    _s.setMessage(message);
                    get_gatewayEventManager().notifyGatewayStartResult(_requestIdentifier, _s);

                }
            }
        });
        return null;
    } else {
        Status _status;
        if (getGatewayStatus() == GatewayStatus.GW_READY_TO_START
                || getGatewayStatus() == GatewayStatus.GW_STOPPED) {
            setGatewayStatus(GatewayStatus.GW_STARTING);

            _status = DataLayer.startGatewayDeviceSync(timeout, sai);

            if (_status.getCode() == GatewayConstants.SUCCESS) {
                _lockerStartDevice.setId(0);
                _lockerStartDevice.getObjectLocker().poll(timeout, TimeUnit.MILLISECONDS);
                if (_lockerStartDevice.getId() > 0) {
                    lastSai = sai;
                    LOG.info("***Gateway Started now!****");
                } else {
                    setGatewayStatus(GatewayStatus.GW_READY_TO_START);

                    LOG.error("Gateway NOT Started!");
                    _status.setCode((short) GatewayConstants.GENERAL_ERROR);
                    _status.setMessage("No Network Event Running received!");
                }
            }

            get_gatewayEventManager().notifyGatewayStartResult(_status);
        } else {
            // ...from all others, throw an exception
            String message = "Trying to start Gateway Device in " + getGatewayStatus() + " state.";
            LOG.debug(message);

            throw new GatewayException(message);
        }
        return SerializationUtils.clone(_status);

    }

}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Resets the GAl with the ability to set whether to delete the
 * NonVolatileMemory to the next reboot/*www . j a  v  a  2  s  .  co m*/
 * 
 * @param timeout
 *            the desired timeout
 * @param _requestIdentifier
 *            the request identifier
 * @param mode
 *            the desired mode
 * @param Async
 *            whether the operation will be asynchronous ({@code true}) or
 *            not ({@code false}).
 * @return the resulting status from ZGD.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */
public Status resetDongle(final long timeout, final int _requestIdentifier, final short mode,
        final boolean Async) throws IOException, Exception, GatewayException {
    if (mode == GatewayConstants.RESET_COMMISSIONING_ASSOCIATION) {
        PropertiesManager.setStartupSet((short) 0x18);
        PropertiesManager.getSturtupAttributeInfo().setStartupControl((short) 0x00);

    } else if (mode == GatewayConstants.RESET_USE_NVMEMORY) {
        PropertiesManager.setStartupSet((short) 0x00);
        PropertiesManager.getSturtupAttributeInfo().setStartupControl((short) 0x04);

    } else if (mode == GatewayConstants.RESET_COMMISSIONING_SILENTSTART) {
        PropertiesManager.setStartupSet((short) 0x18);
        PropertiesManager.getSturtupAttributeInfo().setStartupControl((short) 0x04);
    }
    if (Async) {
        executor.execute(new Runnable() {
            public void run() {
                try {

                    Status _s = new Status();
                    _s.setCode((short) GatewayConstants.SUCCESS);
                    _s.setMessage("Reset Done");
                    initializeGAL();
                    get_gatewayEventManager().notifyResetResult(_s);

                } catch (Exception e) {
                    Status _s = new Status();
                    _s.setCode((short) GatewayConstants.GENERAL_ERROR);
                    _s.setMessage(e.getMessage());
                    get_gatewayEventManager().notifyResetResult(_s);
                }

            }
        });
        return null;
    } else {

        Status _s = new Status();
        _s.setCode((short) GatewayConstants.SUCCESS);
        _s.setMessage("Reset Done");
        initializeGAL();
        get_gatewayEventManager().notifyResetResult(_s);
        return SerializationUtils.clone(_s);
    }

}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Stops the network./*from   w ww . ja va 2s  .  c  o m*/
 * 
 * @param timeout
 *            the desired timeout value.
 * @param _requestIdentifier
 *            the request identifier.
 * @param Async
 *            whether the operation will be asynchronous ({@code true}) or
 *            not ({@code false}).
 * @return the resulting status from ZGD.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */
public Status stopNetwork(final long timeout, final int _requestIdentifier, boolean Async)
        throws Exception, GatewayException {
    if (Async) {
        executor.execute(new Runnable() {
            public void run() {

                if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {
                    setGatewayStatus(GatewayStatus.GW_STOPPING);

                    Status _res = null;
                    try {
                        _res = DataLayer.stopNetworkSync(timeout);
                        get_gatewayEventManager().notifyGatewayStopResult(_res);
                    } catch (GatewayException e) {
                        Status _s = new Status();
                        _s.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s.setMessage(e.getMessage());
                        get_gatewayEventManager().notifyGatewayStopResult(_requestIdentifier, _s);

                    } catch (Exception e) {
                        Status _s = new Status();
                        _s.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s.setMessage(e.getMessage());
                        get_gatewayEventManager().notifyGatewayStopResult(_requestIdentifier, _s);

                    }

                } else {

                    String message = "Trying to stop Gateway Device in " + getGatewayStatus() + " state.";
                    LOG.info(message);

                    Status _s = new Status();
                    _s.setCode((short) GatewayConstants.GENERAL_ERROR);
                    _s.setMessage(message);
                    get_gatewayEventManager().notifyGatewayStopResult(_requestIdentifier, _s);

                }
            }
        });
        return null;
    } else {
        Status _status;
        if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {
            setGatewayStatus(GatewayStatus.GW_STOPPING);
            _status = DataLayer.stopNetworkSync(timeout);
            get_gatewayEventManager().notifyGatewayStopResult(_status);
        } else {
            // ...from all others, throw an exception
            String message = "Trying to stop Gateway Device in " + getGatewayStatus() + " state.";
            throw new GatewayException(message);
        }
        return SerializationUtils.clone(_status);

    }
}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Activation of discovery procedures of the services (the endpoints) for a
 * node connected to the ZigBee network.
 * //  www  . ja  v  a  2s . c o m
 * @param timeout
 *            the desired timout.
 * @param _requestIdentifier
 *            the request identifier.
 * @param aoi
 *            the address of interest.
 * @param Async
 *            whether the operation will be asynchronous ({@code true}) or
 *            not ({@code false}).
 * @return the discovered node services.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */
public NodeServices startServiceDiscovery(final long timeout, final int _requestIdentifier, final Address aoi,
        boolean Async) throws IOException, Exception, GatewayException {
    if (aoi.getNetworkAddress() == null && aoi.getIeeeAddress() != null)
        aoi.setNetworkAddress(getShortAddress_FromIeeeAddress(aoi.getIeeeAddress()));
    if (aoi.getIeeeAddress() == null && aoi.getNetworkAddress() != null)
        aoi.setIeeeAddress(getIeeeAddress_FromShortAddress(aoi.getNetworkAddress()));

    if (Async) {
        executor.execute(new MyRunnable(this) {
            public void run() {
                NodeServices _newNodeService = new NodeServices();
                if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {

                    List<Short> _s = null;
                    try {
                        _s = DataLayer.startServiceDiscoverySync(timeout, aoi);
                        Status _ok = new Status();
                        _ok.setCode((short) 0x00);
                        _newNodeService.setAddress(aoi);

                        for (Short x : _s) {
                            ActiveEndpoints _n = new ActiveEndpoints();
                            _n.setEndPoint(x);
                            _newNodeService.getActiveEndpoints().add(_n);
                        }

                        WrapperWSNNode x = new WrapperWSNNode((GalController) this.getParameter(),
                                String.format("%04X", aoi.getNetworkAddress()));
                        WSNNode node = new WSNNode();
                        node.setAddress(aoi);
                        x.set_node(node);
                        x = getFromNetworkCache(x);
                        if (x != null) {
                            x.set_nodeServices(_newNodeService);
                        }
                        get_gatewayEventManager().notifyServicesDiscovered(_requestIdentifier, _ok,
                                _newNodeService);
                    } catch (IOException e) {
                        _newNodeService.setAddress(aoi);
                        Status _s1 = new Status();
                        _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s1.setMessage(e.getMessage());
                        get_gatewayEventManager().notifyServicesDiscovered(_requestIdentifier, _s1,
                                _newNodeService);
                    } catch (GatewayException e) {
                        _newNodeService.setAddress(aoi);
                        Status _s1 = new Status();
                        _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s1.setMessage(e.getMessage());
                        get_gatewayEventManager().notifyServicesDiscovered(_requestIdentifier, _s1,
                                _newNodeService);
                    } catch (Exception e) {
                        _newNodeService.setAddress(aoi);
                        Status _s1 = new Status();
                        _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s1.setMessage(e.getMessage());
                        get_gatewayEventManager().notifyServicesDiscovered(_requestIdentifier, _s1,
                                _newNodeService);
                    }
                } else {
                    Status _s1 = new Status();
                    _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                    _s1.setMessage("Gal is not in running state");
                    get_gatewayEventManager().notifyServicesDiscovered(_requestIdentifier, _s1,
                            _newNodeService);

                }
            }

        });
        return null;
    } else {
        if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {

            List<Short> _result = DataLayer.startServiceDiscoverySync(timeout, aoi);

            NodeServices _newNodeService = new NodeServices();
            _newNodeService.setAddress(aoi);

            for (Short x : _result) {
                ActiveEndpoints _n = new ActiveEndpoints();
                _n.setEndPoint(x);
                _newNodeService.getActiveEndpoints().add(_n);
            }
            WrapperWSNNode x = new WrapperWSNNode(this, String.format("%04X", aoi.getNetworkAddress()));
            WSNNode node = new WSNNode();
            node.setAddress(aoi);
            x.set_node(node);

            x = getFromNetworkCache(x);
            if (x != null) {
                x.set_nodeServices(_newNodeService);
            }

            return SerializationUtils.clone(_newNodeService);
        } else
            throw new GatewayException("Gal is not in running state!");
    }

}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Returns the list of all callbacks to which you have previously
 * registered.//from  w  ww.jav a  2s  . c  om
 * 
 * @param requestIdentifier
 *            the request identifier.
 * @return the callback's list.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */
public CallbackIdentifierList listCallbacks(int requestIdentifier)
        throws IOException, Exception, GatewayException {
    CallbackIdentifierList toReturn = new CallbackIdentifierList();
    for (CallbackEntry ce : listCallback) {
        if (ce.getProxyIdentifier() == requestIdentifier)
            toReturn.getCallbackIdentifier().add(ce.getCallbackIdentifier());
    }
    return SerializationUtils.clone(toReturn);
}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Disassociates a node from the network.
 * //from w  w  w  .  ja v a2  s  .  c  o m
 * @param timeout
 *            the desired timeout.
 * @param _requestIdentifier
 *            the request identifier.
 * @param addrOfInterest
 *            the address of interest.
 * @param mask
 *            the mask.
 * @param Async
 *            whether the operation will be asynchronous ({@code true}) or
 *            not ({@code false}).
 * @return the resulting status from ZGD.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */
public Status leave(final long timeout, final int _requestIdentifier, final Address addrOfInterest,
        final int mask, final boolean Async) throws IOException, Exception, GatewayException {
    if (addrOfInterest.getNetworkAddress() == null && addrOfInterest.getIeeeAddress() != null)
        addrOfInterest.setNetworkAddress(getShortAddress_FromIeeeAddress(addrOfInterest.getIeeeAddress()));
    if (addrOfInterest.getIeeeAddress() == null && addrOfInterest.getNetworkAddress() != null)
        addrOfInterest.setIeeeAddress(getIeeeAddress_FromShortAddress(addrOfInterest.getNetworkAddress()));

    if (Async) {
        executor.execute(new MyRunnable(this) {
            public void run() {
                Status _s = null;
                if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {

                    if (!addrOfInterest.getNetworkAddress()
                            .equals(GalNode.get_node().getAddress().getNetworkAddress())) {

                        try {

                            leavePhilips(timeout, _requestIdentifier, addrOfInterest);
                            _s = DataLayer.leaveSync(timeout, addrOfInterest, mask);
                            if (_s.getCode() == GatewayConstants.SUCCESS) {
                                /* get the node from cache */
                                WrapperWSNNode x = new WrapperWSNNode((GalController) this.getParameter(),
                                        String.format("%04X", addrOfInterest.getNetworkAddress()));
                                WSNNode node = new WSNNode();
                                node.setAddress(addrOfInterest);
                                x.set_node(node);
                                x = getFromNetworkCache(x);
                                if (x != null) {
                                    x.abortTimers();
                                    get_gatewayEventManager().nodeRemoved(_s, x.get_node());
                                    getNetworkcache().remove(x);
                                    get_gatewayEventManager().notifyleaveResult(_s);
                                    get_gatewayEventManager().notifyleaveResultExtended(_s, addrOfInterest);
                                }
                            }

                        } catch (IOException e) {
                            Status _s1 = new Status();
                            _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                            _s1.setMessage(e.getMessage());
                            get_gatewayEventManager().notifyleaveResult(_requestIdentifier, _s1);
                            get_gatewayEventManager().notifyleaveResultExtended(_requestIdentifier, _s1,
                                    addrOfInterest);

                        } catch (GatewayException e) {
                            Status _s1 = new Status();
                            _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                            _s1.setMessage(e.getMessage());
                            get_gatewayEventManager().notifyleaveResult(_requestIdentifier, _s1);
                            get_gatewayEventManager().notifyleaveResultExtended(_requestIdentifier, _s1,
                                    addrOfInterest);

                        } catch (Exception e) {
                            Status _s1 = new Status();
                            _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                            _s1.setMessage(e.getMessage());
                            get_gatewayEventManager().notifyleaveResult(_requestIdentifier, _s1);
                            get_gatewayEventManager().notifyleaveResultExtended(_requestIdentifier, _s1,
                                    addrOfInterest);

                        }
                    } else {
                        Status _s1 = new Status();
                        _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s1.setMessage("Is not possible Leave the GAL!");
                        get_gatewayEventManager().notifyleaveResult(_requestIdentifier, _s1);
                        get_gatewayEventManager().notifyleaveResultExtended(_requestIdentifier, _s1,
                                addrOfInterest);

                    }

                } else {
                    Status _s1 = new Status();
                    _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                    _s1.setMessage("Gal is not in running state!");
                    get_gatewayEventManager().notifyleaveResult(_requestIdentifier, _s1);
                    get_gatewayEventManager().notifyleaveResultExtended(_requestIdentifier, _s1,
                            addrOfInterest);

                }

            }

        });
        return null;
    } else {
        if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {

            if (!addrOfInterest.getNetworkAddress()
                    .equals(GalNode.get_node().getAddress().getNetworkAddress())) {
                leavePhilips(timeout, _requestIdentifier, addrOfInterest);
                Status _s = DataLayer.leaveSync(timeout, addrOfInterest, mask);
                if (_s.getCode() == GatewayConstants.SUCCESS) {
                    /* get the node from cache */
                    WrapperWSNNode x = new WrapperWSNNode(this,
                            String.format("%04X", addrOfInterest.getNetworkAddress()));
                    WSNNode node = new WSNNode();
                    node.setAddress(addrOfInterest);
                    x.set_node(node);
                    x = getFromNetworkCache(x);
                    if (x != null) {
                        x.abortTimers();
                        get_gatewayEventManager().nodeRemoved(_s, x.get_node());
                        getNetworkcache().remove(x);
                        get_gatewayEventManager().notifyleaveResult(_s);
                        get_gatewayEventManager().notifyleaveResultExtended(_s, addrOfInterest);
                    }
                }

                return SerializationUtils.clone(_s);
            } else
                throw new GatewayException("Is not possible Leave the GAL!");
        } else
            throw new GatewayException("Gal is not in running state!");
    }

}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Opens a ZigBee network to a single node, and for a specified duration, to
 * be able to associate new nodes.//  w  w w  .j  ava  2 s  . c om
 * 
 * @param timeout
 *            the desired timout.
 * @param _requestIdentifier
 *            the request identifier.
 * @param addrOfInterest
 *            the address of interest.
 * @param duration
 *            the duration.
 * @param Async
 *            whether the operation will be asynchronous ({@code true}) or
 *            not ({@code false}).
 * @return the resulting status from ZGD.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */
public Status permitJoin(final long timeout, final int _requestIdentifier, final Address addrOfInterest,
        final short duration, final boolean Async) throws IOException, GatewayException, Exception {
    if (Async) {
        executor.execute(new Runnable() {
            public void run() {

                Status _s = new Status();
                if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {

                    try {
                        _s = DataLayer.permitJoinSync(timeout, addrOfInterest, duration, (byte) 0x00);
                        get_gatewayEventManager().notifypermitJoinResult(_s);
                    } catch (IOException e) {
                        Status _s1 = new Status();
                        _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s1.setMessage(e.getMessage());
                        get_gatewayEventManager().notifypermitJoinResult(_requestIdentifier, _s1);
                    } catch (GatewayException e) {
                        Status _s1 = new Status();
                        _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s1.setMessage(e.getMessage());
                        get_gatewayEventManager().notifypermitJoinResult(_requestIdentifier, _s1);
                    } catch (Exception e) {
                        Status _s1 = new Status();
                        _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s1.setMessage(e.getMessage());
                        get_gatewayEventManager().notifypermitJoinResult(_requestIdentifier, _s1);
                    }
                } else {
                    Status _s1 = new Status();
                    _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                    _s1.setMessage("Gal is not in running state!");
                    get_gatewayEventManager().notifypermitJoinResult(_requestIdentifier, _s1);
                }

            }

        });
        return null;
    } else {
        Status _s;
        if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {

            try {
                _s = DataLayer.permitJoinSync(timeout, addrOfInterest, duration, (byte) 0x00);
                get_gatewayEventManager().notifypermitJoinResult(_s);
                return SerializationUtils.clone(_s);
            } catch (IOException e) {
                Status _s1 = new Status();
                _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                _s1.setMessage(e.getMessage());
                get_gatewayEventManager().notifypermitJoinResult(_requestIdentifier, _s1);
                throw e;
            } catch (GatewayException e) {
                Status _s1 = new Status();
                _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                _s1.setMessage(e.getMessage());
                get_gatewayEventManager().notifypermitJoinResult(_requestIdentifier, _s1);
                throw e;
            } catch (Exception e) {
                Status _s1 = new Status();
                _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                _s1.setMessage(e.getMessage());
                get_gatewayEventManager().notifypermitJoinResult(_requestIdentifier, _s1);
                throw e;
            }
        } else
            throw new GatewayException("Gal is not in running state!");
    }

}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Allows the opening of the ZigBee network to all nodes, and for a
 * specified duration, to be able to associate new nodes
 * /*from   ww w  . ja  v  a 2 s . c o m*/
 * @param timeout
 *            the desired timout.
 * @param _requestIdentifier
 *            the request identifier.
 * @param duration
 *            the duration.
 * @param Async
 *            whether the operation will be asynchronous ({@code true}) or
 *            not ({@code false}).
 * @return the resulting status from ZGD.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 */
public Status permitJoinAll(final long timeout, final int _requestIdentifier, final short duration,
        final boolean Async) throws IOException, Exception {
    final Address _add = new Address();
    _add.setNetworkAddress(0xFFFC);
    if (Async) {
        executor.execute(new Runnable() {
            public void run() {
                Status _s;
                if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {

                    try {
                        _s = DataLayer.permitJoinAllSync(timeout, _add, duration, (byte) 0x00);
                        get_gatewayEventManager().notifypermitJoinResult(_s);
                    } catch (IOException e) {
                        Status _s1 = new Status();
                        _s1.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s1.setMessage(e.getMessage());
                        get_gatewayEventManager().notifypermitJoinResult(_s1);
                    } catch (Exception e) {
                        Status _s2 = new Status();
                        _s2.setCode((short) GatewayConstants.GENERAL_ERROR);
                        _s2.setMessage(e.getMessage());
                        get_gatewayEventManager().notifypermitJoinResult(_s2);
                    }
                } else {

                    Status _s2 = new Status();
                    _s2.setCode((short) GatewayConstants.GENERAL_ERROR);
                    _s2.setMessage("Gal is not in running state!");
                    get_gatewayEventManager().notifypermitJoinResult(_s2);
                }

            }
        });
        return null;
    } else {
        if (getGatewayStatus() == GatewayStatus.GW_RUNNING) {

            Status _s = DataLayer.permitJoinAllSync(timeout, _add, duration, (byte) 0x00);
            get_gatewayEventManager().notifypermitJoinResult(_s);
            return SerializationUtils.clone(_s);
        } else
            throw new GatewayException("Gal is not in running state!");
    }
}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Gets the version for the ZigBee Gateway Device.
 * //  ww  w  .j a  v a 2s .c  om
 * @return the version
 * @see Version
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */
public static Version getVersion() throws IOException, Exception, GatewayException {
    Version v = new Version();
    org.osgi.framework.Version version = FrameworkUtil.getBundle(GalController.class).getVersion();
    v.setManufacturerVersion(version.getMajor() + "." + version.getMinor() + "." + version.getMicro());
    v.getRPCProtocol().add(RPCProtocol.REST);
    return SerializationUtils.clone(v);
}

From source file:org.energy_home.jemma.javagal.layers.business.GalController.java

/**
 * Removes a SimpleDescriptor or an endpoint.
 * //from   w  w  w  .  j a  va 2  s .c  o m
 * @param endpoint
 *            the endpoint to remove
 * @return the resulting status from ZGD.
 * @throws IOException
 *             if an Input Output error occurs.
 * @throws Exception
 *             if a general error occurs.
 * @throws GatewayException
 *             if a ZGD error occurs.
 */
public Status clearEndpoint(short endpoint) throws IOException, Exception, GatewayException {
    Status _s = DataLayer.clearEndpointSync(getPropertiesManager().getCommandTimeoutMS(), endpoint);
    return SerializationUtils.clone(_s);
}