List of usage examples for org.apache.commons.lang3 SerializationUtils clone
public static <T extends Serializable> T clone(final T object)
Deep clone an Object using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Gets the service descriptor for an endpoint. * /*from ww w. jav a 2s .c o m*/ * @param timeout * the desired timeout. * @param _requestIdentifier * the request identifier. * @param addrOfInterest * the address of interest. * @param endpoint * the endpoint * @param Async * whether the operation will be asynchronous ({@code true}) or * not ({@code false}). * @return the simple descriptor. * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public ServiceDescriptor getServiceDescriptor(final long timeout, final int _requestIdentifier, final Address addrOfInterest, final short endpoint, 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 Runnable() { public void run() { ServiceDescriptor _toRes = new ServiceDescriptor(); if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { try { Status _s = new Status(); _s.setCode((short) GatewayConstants.SUCCESS); _toRes = DataLayer.getServiceDescriptor(timeout, addrOfInterest, endpoint); _toRes.setAddress(addrOfInterest); get_gatewayEventManager().notifyserviceDescriptorRetrieved(_requestIdentifier, _s, _toRes); } catch (GatewayException e) { _toRes.setAddress(addrOfInterest); Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifyserviceDescriptorRetrieved(_requestIdentifier, _s, _toRes); } catch (Exception e) { _toRes.setAddress(addrOfInterest); Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifyserviceDescriptorRetrieved(_requestIdentifier, _s, _toRes); } } else { _toRes.setAddress(addrOfInterest); Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage("Gal is not in running state!"); get_gatewayEventManager().notifyserviceDescriptorRetrieved(_requestIdentifier, _s, _toRes); } } }); return null; } else { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { ServiceDescriptor _toRes; _toRes = DataLayer.getServiceDescriptor(timeout, addrOfInterest, endpoint); _toRes.setAddress(addrOfInterest); return SerializationUtils.clone(_toRes); } else throw new GatewayException("Gal is not in running state!"); } }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Gets a list of all bindings stored in a remote node, starting from a * given index./*from w w w . j av a2 s .c o m*/ * * @param timeout * the desired timeout * @param _requestIdentifier * the request identifier * @param aoi * the address of interest * @param index * the index from where to start * @param Async * whether the operation will be asynchronous ({@code true}) or * not ({@code false}). * @return the binding list * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public BindingList getNodeBindingsSync(final long timeout, final int _requestIdentifier, final Address aoi, final short index, 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 Runnable() { public void run() { BindingList _toRes = new BindingList(); if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { try { Status _s = new Status(); _s.setCode((short) GatewayConstants.SUCCESS); _toRes = DataLayer.getNodeBindings(timeout, aoi, index); get_gatewayEventManager().notifynodeBindingsRetrieved(_requestIdentifier, _s, _toRes); } catch (GatewayException e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifynodeBindingsRetrieved(_requestIdentifier, _s, _toRes); } catch (Exception e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifynodeBindingsRetrieved(_requestIdentifier, _s, _toRes); } } else { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage("Gal is not in running state!"); get_gatewayEventManager().notifynodeBindingsRetrieved(_requestIdentifier, _s, _toRes); } } }); return null; } else { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { BindingList _toRes; _toRes = DataLayer.getNodeBindings(timeout, aoi, index); return SerializationUtils.clone(_toRes); } else throw new GatewayException("Gal is not in running state!"); } }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Adds a binding./*from ww w . j a v a2s . c om*/ * * @param timeout * @param _requestIdentifier * @param binding * the binding * @param Async * whether the operation will be asynchronous ({@code true}) or * not ({@code false}). * @return the resulting status from ZGD. * @see Binding * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public Status addBindingSync(final long timeout, final int _requestIdentifier, final Binding binding, final boolean Async) throws IOException, Exception, GatewayException { final Address aoi = new Address(); aoi.setIeeeAddress(binding.getSourceIEEEAddress()); aoi.setNetworkAddress(getShortAddress_FromIeeeAddress(aoi.getIeeeAddress())); if (Async) { executor.execute(new Runnable() { public void run() { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { try { Status _s = DataLayer.addBinding(timeout, binding, aoi); get_gatewayEventManager().notifybindingResult(_requestIdentifier, _s); } catch (GatewayException e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifybindingResult(_requestIdentifier, _s); } catch (Exception e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifybindingResult(_requestIdentifier, _s); } } else { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage("Gal is not in running state!"); get_gatewayEventManager().notifybindingResult(_requestIdentifier, _s); } } }); return null; } else { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) return SerializationUtils.clone(DataLayer.addBinding(timeout, binding, aoi)); else throw new GatewayException("Gal is not in running state!"); } }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Removes a binding.//from www.j av a 2s. c o m * * @param timeout * the desired binding * @param _requestIdentifier * the request identifier * @param binding * the binding * @param Async * whether the operation will be asynchronous ({@code true}) or * not ({@code false}). * @return the resulting status from ZGD. * @see Binding * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public Status removeBindingSync(final long timeout, final int _requestIdentifier, final Binding binding, final boolean Async) throws IOException, Exception, GatewayException { final Address aoi = new Address(); aoi.setIeeeAddress(binding.getSourceIEEEAddress()); aoi.setNetworkAddress(getShortAddress_FromIeeeAddress(aoi.getIeeeAddress())); if (Async) { executor.execute(new Runnable() { public void run() { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { try { Status _s = DataLayer.removeBinding(timeout, binding, aoi); get_gatewayEventManager().notifyUnbindingResult(_requestIdentifier, _s); } catch (GatewayException e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifyUnbindingResult(_requestIdentifier, _s); } catch (Exception e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifyUnbindingResult(_requestIdentifier, _s); } } else { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage("Gal is not in running state!"); get_gatewayEventManager().notifyUnbindingResult(_requestIdentifier, _s); } } }); return null; } else { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) return SerializationUtils.clone(DataLayer.removeBinding(timeout, binding, aoi)); else throw new GatewayException("Gal is not in running state!"); } }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Frequency agility method.//ww w.j a va 2s .co m * * @param timeout * the desired timeout * @param _requestIdentifier * the request identifier * @param scanChannel * the channel to scan * @param scanDuration * the desired duration of the scan * @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 frequencyAgilitySync(final long timeout, final int _requestIdentifier, final short scanChannel, final short scanDuration, final boolean Async) throws IOException, Exception, GatewayException { if (Async) { executor.execute(new Runnable() { public void run() { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { try { Status _st = DataLayer.frequencyAgilitySync(timeout, scanChannel, scanDuration); get_gatewayEventManager().notifyFrequencyAgility(_st); } catch (GatewayException e) { Status _st = new Status(); _st.setCode((short) GatewayConstants.GENERAL_ERROR); _st.setMessage(e.getMessage()); get_gatewayEventManager().notifyFrequencyAgility(_st); } catch (Exception e) { Status _st = new Status(); _st.setCode((short) GatewayConstants.GENERAL_ERROR); _st.setMessage(e.getMessage()); get_gatewayEventManager().notifyFrequencyAgility(_st); } } else { Status _st = new Status(); _st.setCode((short) GatewayConstants.GENERAL_ERROR); _st.setMessage("Gal is not in running state!"); get_gatewayEventManager().notifyFrequencyAgility(_st); } } }); return null; } else { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { Status _st = DataLayer.frequencyAgilitySync(timeout, scanChannel, scanDuration); return SerializationUtils.clone(_st); } else throw new GatewayException("Gal is not in running state!"); } }
From source file:org.energy_home.jemma.javagal.layers.business.implementations.ApsMessageManager.java
/** * Processes the APS indication message trying to dispatch it to the right * destination. The {@link GalController} maintains a collection of * registered callbacks' listeners. This method verifies if a match exists * on that collection for the callback's filter, i.e. looks if one or more * destination(s) for that APS message is present. If it exists, sends the * APS message to all found destinations. * //from www. j a v a 2 s.c o m * @param message * the indication APSMessageEvent to process. */ @Deprecated public void APSMessageIndication(final APSMessageEvent message) { executor.execute(new Runnable() { public void run() { LOG.debug("GAL-Aps Message Indication in process..."); for (CallbackEntry ce : getGal().getCallbacks()) { Callback callback = ce.getCallback(); Filter filter = callback.getFilter(); if (filter.getLevelSpecification().getLevel().get(0).equals(Level.APS_LEVEL)) { if (filter.getMessageSpecification().size() > 0) { boolean messageSpecificationFound = false; for (MessageSpecification ms : filter.getMessageSpecification()) { if (ms.getAPSClusterIdentifier() == null) { messageSpecificationFound = true; // If match we can stop the search loop. break; } else if (ms.getAPSClusterIdentifier() == message.getClusterID()) { messageSpecificationFound = true; // If match we can stop the search loop. break; } } if (!messageSpecificationFound) { // If no Messaging Specification was found, // then this callback doesn't match and we // can jump to check the next one. continue; } } // Address Specification check. If there are at // least one address specification in the filter, // then we proceed to find a match, else if no // address specification is present we assume that // the check pass. if (filter.getAddressSpecification().size() > 0) { boolean addressingSpecificationFound = false; for (AddressSpecification as : filter.getAddressSpecification()) { // Source Address (Address Specification) Address assa = as.getNWKSourceAddress(); int asnsa = 0xFFFF; // If null, then we assume that all address // match for this filter, and so we leave // the initial value of 0xFFFF. if (assa != null) { asnsa = assa.getNetworkAddress(); } short assep = -1; if (as.getAPSSourceEndpoint() != null) assep = as.getAPSSourceEndpoint(); // Pass if the callback has a broadcast // Source Address if (asnsa != 0xFFFF) { // Source Address long msam = message.getSourceAddressMode().longValue(); Address msa = message.getSourceAddress(); if (msam == 0x01) { // Network address, NO source end // point int msna0x01 = msa.getNetworkAddress(); // Pass if the message has a // broadcast Source Address if (msna0x01 != 0xFFFF) { // Don't pass if they differs, // so we go ahead on the next // iteration in the for cycle if (asnsa != msna0x01) { continue; } } } else if (msam == 0x02) { // Network address, AND source end // point present. int msna0x02 = msa.getNetworkAddress(); short msep = message.getSourceEndpoint(); // Pass if the message has a // broadcast Source Address. if (msna0x02 != 0xFFFF) { // Don't pass if they differs, // so we go ahead on the // next iteration in for cycle. if (asnsa != msna0x02) { // Don't pass if they // differs, so we go ahead // on the next iteration in // the for cycle. continue; } else if (msep != 0xFF) { if (msep != assep) { // Don't pass if they // differs, so we go // ahead on the next // iteration in the for // cycle. continue; } } } } else if (msam == 0x03) { LOG.info("AIA"); // ASK No ieee address defined in // the AddressSpecification // object. We do nothing since we // can't compare the values. } } // If reached this point, then a matching // Source Address is found for the current // AddressSpecification. So we can proceed // to check the Destination End Point. // Destination End Point (Address // Specification) if (as.getAPSDestinationEndpoint() == null) { addressingSpecificationFound = true; break; } else { short asdep = as.getAPSDestinationEndpoint(); // Pass if the callback has a broadcast // Destination End Point if (asdep != 0xFF) { long dam = message.getDestinationAddressMode(); // 0x00 and 0x01 Destination End // Point // not present if (dam > 0x01) { short mdep = message.getDestinationEndpoint(); // Pass if the message has a // broadcast Destination End // Point if (mdep != 0xFF) { // Don't pass if they // differs, // so we go ahead on the // next // iteration in the for // cycle if ((asdep != mdep) && (mdep != ((byte) 0xFF))) { continue; } } } } } // If reached this point, then a matching // Destination End Point is also found for // the current AddressSpecification. This // means that a matching Addressing // Specification is found. We can stop here // the loop since one match it's enough. addressingSpecificationFound = true; break; } if (!addressingSpecificationFound) { // If no Addressing Specification was found, // then this callback doesn't match and we // can jump to check the next one. continue; } } // If this point is reached, then a matching // callback is found. Notify the message to its // destination. APSMessageListener apml = ce.getDestination(); if (apml != null) apml.notifyAPSMessage(message); MessageListener napml = ce.getGenericDestination(); if (napml != null) { APSMessageEvent cmessage = null; synchronized (message) { cmessage = SerializationUtils.clone(message); } LOG.debug("READY to CallBack NotifyApsMessage: {}", ((cmessage.getDestinationAddress().getNetworkAddress() != null) ? String.format( "%04X", cmessage.getDestinationAddress().getNetworkAddress()) : "")); napml.notifyAPSMessage(cmessage); } // Add it to the list of already notified // destinations. } } LOG.debug("Aps Message Indication done!"); } }); }
From source file:org.energy_home.jemma.javagal.layers.business.implementations.GatewayEventManager.java
/** * {@inheritDoc}// w w w. ja v a2 s .c om */ public void notifyGatewayStartResult(final Status status) { executor.execute(new Runnable() { public void run() { for (GatewayDeviceEventEntry<?> gel : getGal().getListGatewayEventListener()) { Status cstatus = null; synchronized (status) { cstatus = SerializationUtils.clone(status); } gel.getGatewayEventListener().gatewayStartResult(cstatus); } } }); }
From source file:org.energy_home.jemma.javagal.layers.business.implementations.GatewayEventManager.java
/** * {@inheritDoc}/* ww w .j ava2 s . com*/ */ public void notifyGatewayStartResult(final int _requestIdentifier, final Status status) { executor.execute(new Runnable() { public void run() { for (GatewayDeviceEventEntry<?> gel : getGal().getListGatewayEventListener()) { if (gel.getProxyIdentifier() == _requestIdentifier) { Status cstatus = null; synchronized (status) { cstatus = SerializationUtils.clone(status); } gel.getGatewayEventListener().gatewayStartResult(cstatus); } } } }); }
From source file:org.energy_home.jemma.javagal.layers.business.implementations.GatewayEventManager.java
/** * {@inheritDoc}// w ww .j a v a 2 s. c om */ public void notifyServicesDiscovered(final int _requestIdentifier, final Status status, final NodeServices nodeServices) { executor.execute(new Runnable() { public void run() { for (GatewayDeviceEventEntry<?> gel : getGal().getListGatewayEventListener()) { if (gel.getProxyIdentifier() == _requestIdentifier) { Status cstatus = null; NodeServices cnodeServices = null; synchronized (status) { cstatus = SerializationUtils.clone(status); } synchronized (nodeServices) { cnodeServices = SerializationUtils.clone(nodeServices); } gel.getGatewayEventListener().servicesDiscovered(cstatus, cnodeServices); } } } }); }
From source file:org.energy_home.jemma.javagal.layers.business.implementations.GatewayEventManager.java
/** * {@inheritDoc}/* www. ja va 2 s .co m*/ */ public void notifyGatewayStopResult(final Status status) { executor.execute(new Runnable() { public void run() { for (GatewayDeviceEventEntry<?> gl : getGal().getListGatewayEventListener()) { if (gl.getGatewayEventListener() instanceof GatewayEventListenerExtended) { Status cstatus = null; synchronized (status) { cstatus = SerializationUtils.clone(status); } ((GatewayEventListenerExtended) gl.getGatewayEventListener()).gatewayStopResult(cstatus); } } } }); }