use of java.util.TooManyListenersException in project openhab1-addons by openhab.
the class ZWaveController method connect.
// Controller methods
/**
* Connects to the comm port and starts send and receive threads.
*
* @param serialPortName the port name to open
* @throws SerialInterfaceException when a connection error occurs.
*/
public void connect(final String serialPortName) throws SerialInterfaceException {
logger.info("Connecting to serial port {}", serialPortName);
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
CommPort commPort = portIdentifier.open("org.openhab.binding.zwave", 2000);
this.serialPort = (SerialPort) commPort;
this.serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
this.serialPort.enableReceiveThreshold(1);
this.serialPort.enableReceiveTimeout(ZWAVE_RECEIVE_TIMEOUT);
this.receiveThread = new ZWaveReceiveThread();
this.receiveThread.start();
this.sendThread = new ZWaveSendThread();
this.sendThread.start();
this.inputThread = new ZWaveInputThread();
this.inputThread.start();
// RXTX serial port library causes high CPU load
// Start event listener, which will just sleep and slow down event loop
serialPort.addEventListener(this.receiveThread);
serialPort.notifyOnDataAvailable(true);
logger.info("Serial port is initialized");
} catch (NoSuchPortException e) {
logger.error("Serial Error: Port {} does not exist", serialPortName);
throw new SerialInterfaceException(String.format("Port %s does not exist", serialPortName), e);
} catch (PortInUseException e) {
logger.error("Serial Error: Port {} in use.", serialPortName);
throw new SerialInterfaceException(String.format("Port %s in use.", serialPortName), e);
} catch (UnsupportedCommOperationException e) {
logger.error("Serial Error: Unsupported comm operation on Port {}.", serialPortName);
throw new SerialInterfaceException(String.format("Unsupported comm operation on Port %s.", serialPortName), e);
} catch (TooManyListenersException e) {
logger.error("Serial Error: Too many listeners on Port {}.", serialPortName);
e.printStackTrace();
}
}
use of java.util.TooManyListenersException in project openhab1-addons by openhab.
the class CULSerialHandlerImpl method openHardware.
@Override
protected void openHardware() throws CULDeviceException {
String deviceName = config.getDeviceAddress();
logger.debug("Opening serial CUL connection for {}", deviceName);
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(deviceName);
if (portIdentifier.isCurrentlyOwned()) {
throw new CULDeviceException("The port " + deviceName + " is currenty used by " + portIdentifier.getCurrentOwner());
}
CommPort port = portIdentifier.open(this.getClass().getName(), 2000);
if (!(port instanceof SerialPort)) {
throw new CULDeviceException("The device " + deviceName + " is not a serial port");
}
serialPort = (SerialPort) port;
serialPort.setSerialPortParams(config.getBaudRate(), SerialPort.DATABITS_8, SerialPort.STOPBITS_1, config.getParityMode());
InputStream is = serialPort.getInputStream();
OutputStream os = serialPort.getOutputStream();
synchronized (serialPort) {
br = new BufferedReader(new InputStreamReader(is));
bw = new BufferedWriter(new OutputStreamWriter(os));
}
serialPort.notifyOnDataAvailable(true);
logger.debug("Adding serial port event listener");
serialPort.addEventListener(this);
} catch (NoSuchPortException e) {
throw new CULDeviceException(e);
} catch (PortInUseException e) {
throw new CULDeviceException(e);
} catch (UnsupportedCommOperationException e) {
throw new CULDeviceException(e);
} catch (IOException e) {
throw new CULDeviceException(e);
} catch (TooManyListenersException e) {
throw new CULDeviceException(e);
}
}
use of java.util.TooManyListenersException in project openhab1-addons by openhab.
the class ComfoAirConnector method open.
/**
* Open and initialize a serial port.
*
* @param portName
* e.g. /dev/ttyS0
* @param listener
* the listener which is informed after a successful response
* read
* @throws InitializationException
*/
public void open(String portName) throws InitializationException {
logger.debug("Open ComfoAir connection");
port = portName;
CommPortIdentifier portIdentifier;
try {
portIdentifier = CommPortIdentifier.getPortIdentifier(port);
try {
serialPort = portIdentifier.open("openhab", 3000);
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.enableReceiveThreshold(1);
serialPort.enableReceiveTimeout(1000);
// RXTX serial port library causes high CPU load
// Start event listener, which will just sleep and slow down event loop
serialPort.addEventListener(new CPUWorkaroundThread());
serialPort.notifyOnDataAvailable(true);
inputStream = new DataInputStream(new BufferedInputStream(serialPort.getInputStream()));
outputStream = serialPort.getOutputStream();
ComfoAirCommand command = ComfoAirCommandType.getChangeCommand(ComfoAirCommandType.ACTIVATE.key, new DecimalType(1));
sendCommand(command);
} catch (PortInUseException e) {
throw new InitializationException(e);
} catch (UnsupportedCommOperationException e) {
throw new InitializationException(e);
} catch (IOException e) {
throw new InitializationException(e);
} catch (TooManyListenersException e) {
throw new InitializationException(e);
}
} catch (NoSuchPortException e) {
StringBuilder sb = new StringBuilder();
@SuppressWarnings("rawtypes") Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
sb.append(id.getName() + "\n");
}
}
throw new InitializationException("Serial port '" + port + "' could not be found. Available ports are:\n" + sb.toString());
}
}
use of java.util.TooManyListenersException in project roboguice by roboguice.
the class ThrowingProviderTest method testProviderMethodWithManyExceptions.
public void testProviderMethodWithManyExceptions() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(RemoteProvider.class)
String foo() throws InterruptedException, RuntimeException, RemoteException, AccessException, TooManyListenersException {
return null;
}
});
fail();
} catch (CreationException ce) {
// The only two that should fail are Interrupted & TooManyListeners.. the rest are OK.
List<Message> errors = ImmutableList.copyOf(ce.getErrorMessages());
assertEquals(InterruptedException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(0).getMessage());
assertEquals(TooManyListenersException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(1).getMessage());
assertEquals(2, errors.size());
}
}
use of java.util.TooManyListenersException in project guice by google.
the class ThrowingProviderTest method testProviderMethodWithManyExceptions.
public void testProviderMethodWithManyExceptions() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(RemoteProvider.class)
String foo() throws InterruptedException, RuntimeException, RemoteException, AccessException, TooManyListenersException {
return null;
}
});
fail();
} catch (CreationException ce) {
// The only two that should fail are Interrupted & TooManyListeners.. the rest are OK.
List<Message> errors = ImmutableList.copyOf(ce.getErrorMessages());
assertEquals(InterruptedException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(0).getMessage());
assertEquals(TooManyListenersException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(1).getMessage());
assertEquals(2, errors.size());
}
}
Aggregations