public void propertyChange(PropertyChangeEvent e) { log.finer("Property change event on local service: " + e.getPropertyName()); // Prevent recursion if (e.getPropertyName().equals(EVENTED_STATE_VARIABLES)) return; String[] variableNames = ModelUtil.fromCommaSeparatedList(e.getPropertyName()); log.fine("Changed variable names: " + Arrays.toString(variableNames)); try { Collection<StateVariableValue> currentValues = getCurrentState(variableNames); if (!currentValues.isEmpty()) { getPropertyChangeSupport() .firePropertyChange(EVENTED_STATE_VARIABLES, null, currentValues); } } catch (Exception ex) { // TODO: Is it OK to only log this error? It means we keep running although we couldn't send // events? log.log( Level.SEVERE, "Error reading state of service after state variable update event: " + Exceptions.unwrap(ex), ex); } }
/** * Create a new instance of a {@link DLNAHeader} subtype that matches the given type and value. * * <p>This method iterates through all potential header subtype classes as declared in {@link * Type}. It creates a new instance of the subtype class and calls its {@link #setString(String)} * method. If no {@link org.fourthline.cling.model.message.header.InvalidHeaderException} is * thrown, the subtype instance is returned. * * @param type The type (or name) of the header. * @param headerValue The value of the header. * @return The best matching header subtype instance, or <code>null</code> if no subtype can be * found. */ public static DLNAHeader newInstance(DLNAHeader.Type type, String headerValue) { // Try all the UPnP headers and see if one matches our value parsers DLNAHeader upnpHeader = null; for (int i = 0; i < type.getHeaderTypes().length && upnpHeader == null; i++) { Class<? extends DLNAHeader> headerClass = type.getHeaderTypes()[i]; try { log.finest("Trying to parse '" + type + "' with class: " + headerClass.getSimpleName()); upnpHeader = headerClass.newInstance(); if (headerValue != null) { upnpHeader.setString(headerValue); } } catch (InvalidHeaderException ex) { log.finest( "Invalid header value for tested type: " + headerClass.getSimpleName() + " - " + ex.getMessage()); upnpHeader = null; } catch (Exception ex) { log.severe("Error instantiating header of type '" + type + "' with value: " + headerValue); log.log(Level.SEVERE, "Exception root cause: ", Exceptions.unwrap(ex)); } } return upnpHeader; }
protected void shutdownRouter() { try { getRouter().shutdown(); } catch (RouterException ex) { Throwable cause = Exceptions.unwrap(ex); if (cause instanceof InterruptedException) { log.log(Level.INFO, "Router shutdown was interrupted: " + ex, cause); } else { throw new RuntimeException("Router error on shutdown: " + ex, ex); } } }
public void run() { try { execute(); } catch (Exception ex) { Throwable cause = Exceptions.unwrap(ex); if (cause instanceof InterruptedException) { log.log( Level.INFO, "Interrupted protocol '" + getClass().getSimpleName() + "': " + ex, cause); } else { throw new RuntimeException( "Fatal error while executing protocol '" + getClass().getSimpleName() + "': " + ex, ex); } } }