Search in sources :

Example 11 with TooManyListenersException

use of java.util.TooManyListenersException in project XobotOS by xamarin.

the class SipSessionGroup method reset.

synchronized void reset(String localIp) throws SipException, IOException {
    mLocalIp = localIp;
    if (localIp == null)
        return;
    SipProfile myself = mLocalProfile;
    SipFactory sipFactory = SipFactory.getInstance();
    Properties properties = new Properties();
    properties.setProperty("javax.sip.STACK_NAME", getStackName());
    properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE", THREAD_POOL_SIZE);
    String outboundProxy = myself.getProxyAddress();
    if (!TextUtils.isEmpty(outboundProxy)) {
        Log.v(TAG, "outboundProxy is " + outboundProxy);
        properties.setProperty("javax.sip.OUTBOUND_PROXY", outboundProxy + ":" + myself.getPort() + "/" + myself.getProtocol());
    }
    SipStack stack = mSipStack = sipFactory.createSipStack(properties);
    try {
        SipProvider provider = stack.createSipProvider(stack.createListeningPoint(localIp, allocateLocalPort(), myself.getProtocol()));
        provider.addSipListener(this);
        mSipHelper = new SipHelper(stack, provider);
    } catch (InvalidArgumentException e) {
        throw new IOException(e.getMessage());
    } catch (TooManyListenersException e) {
        // must never happen
        throw new SipException("SipSessionGroup constructor", e);
    }
    Log.d(TAG, " start stack for " + myself.getUriString());
    stack.start();
    mCallReceiverSession = null;
    mSessionMap.clear();
    resetExternalAddress();
}
Also used : TooManyListenersException(java.util.TooManyListenersException) InvalidArgumentException(javax.sip.InvalidArgumentException) SipProfile(android.net.sip.SipProfile) SipFactory(javax.sip.SipFactory) SipStack(javax.sip.SipStack) IOException(java.io.IOException) Properties(java.util.Properties) SipException(javax.sip.SipException) SipProvider(javax.sip.SipProvider)

Example 12 with TooManyListenersException

use of java.util.TooManyListenersException in project jdk8u_jdk by JetBrains.

the class DisposeFrameOnDragTest method constructTestUI.

private static void constructTestUI() {
    final JFrame frame = new JFrame("Test frame");
    textArea = new JTextArea("Drag Me!");
    try {
        textArea.getDropTarget().addDropTargetListener(new DropTargetAdapter() {

            @Override
            public void drop(DropTargetDropEvent dtde) {
            //IGNORE
            }

            @Override
            public void dragOver(DropTargetDragEvent dtde) {
                frame.dispose();
            }
        });
    } catch (TooManyListenersException ex) {
        throw new RuntimeException(ex);
    }
    textArea.setSize(100, 100);
    textArea.setDragEnabled(true);
    textArea.select(0, textArea.getText().length());
    frame.add(textArea);
    frame.setBounds(100, 100, 100, 100);
    frame.setVisible(true);
}
Also used : DropTargetAdapter(java.awt.dnd.DropTargetAdapter) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) TooManyListenersException(java.util.TooManyListenersException) JTextArea(javax.swing.JTextArea) JFrame(javax.swing.JFrame) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 13 with TooManyListenersException

use of java.util.TooManyListenersException in project JMRI by JMRI.

the class SerialDriverAdapter method openPort.

@Override
public String openPort(String portName, String appName) {
    try {
        // get and open the primary port
        CommPortIdentifier portID = CommPortIdentifier.getPortIdentifier(portName);
        try {
            // name of program, msec to wait
            activeSerialPort = (SerialPort) portID.open(appName, 2000);
        } catch (PortInUseException p) {
            return handlePortBusy(p, portName, log);
        }
        // try to set it for serial
        try {
            setSerialPort();
        } catch (gnu.io.UnsupportedCommOperationException e) {
            log.error("Cannot set serial parameters on port " + portName + ": " + e.getMessage());
            return "Cannot set serial parameters on port " + portName + ": " + e.getMessage();
        }
        // set receive timeout; framing not in use
        try {
            activeSerialPort.enableReceiveTimeout(10);
            log.debug("Serial timeout was observed as: " + activeSerialPort.getReceiveTimeout() + " " + activeSerialPort.isReceiveTimeoutEnabled());
        } catch (UnsupportedCommOperationException et) {
            log.info("failed to set serial timeout: " + et);
        }
        // get and save stream
        serialStream = activeSerialPort.getInputStream();
        // purge contents, if any
        purgeStream(serialStream);
        // report status?
        if (log.isInfoEnabled()) {
            // report now
            log.info(portName + " port opened at " + activeSerialPort.getBaudRate() + " baud with" + " DTR: " + activeSerialPort.isDTR() + " RTS: " + activeSerialPort.isRTS() + " DSR: " + activeSerialPort.isDSR() + " CTS: " + activeSerialPort.isCTS() + "  CD: " + activeSerialPort.isCD());
        }
        if (log.isDebugEnabled()) {
            // report additional status
            log.debug(" port flow control shows " + (activeSerialPort.getFlowControlMode() == SerialPort.FLOWCONTROL_RTSCTS_OUT ? "hardware flow control" : "no flow control"));
        }
        if (log.isDebugEnabled()) {
            // arrange to notify later
            activeSerialPort.addEventListener((SerialPortEvent e) -> {
                int type = e.getEventType();
                switch(type) {
                    case SerialPortEvent.DATA_AVAILABLE:
                        log.info("SerialEvent: DATA_AVAILABLE is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                        log.info("SerialEvent: OUTPUT_BUFFER_EMPTY is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.CTS:
                        log.info("SerialEvent: CTS is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.DSR:
                        log.info("SerialEvent: DSR is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.RI:
                        log.info("SerialEvent: RI is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.CD:
                        log.info("SerialEvent: CD is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.OE:
                        log.info("SerialEvent: OE (overrun error) is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.PE:
                        log.info("SerialEvent: PE (parity error) is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.FE:
                        log.info("SerialEvent: FE (framing error) is {}", e.getNewValue());
                        return;
                    case SerialPortEvent.BI:
                        log.info("SerialEvent: BI (break interrupt) is {}", e.getNewValue());
                        return;
                    default:
                        log.info("SerialEvent of unknown type: {} value: {}", type, e.getNewValue());
                }
            });
            try {
                activeSerialPort.notifyOnFramingError(true);
            } catch (Exception e) {
                log.debug("Could not notifyOnFramingError: " + e);
            }
            try {
                activeSerialPort.notifyOnBreakInterrupt(true);
            } catch (Exception e) {
                log.debug("Could not notifyOnBreakInterrupt: " + e);
            }
            try {
                activeSerialPort.notifyOnParityError(true);
            } catch (Exception e) {
                log.debug("Could not notifyOnParityError: " + e);
            }
            try {
                activeSerialPort.notifyOnOverrunError(true);
            } catch (Exception e) {
                log.debug("Could not notifyOnOverrunError: " + e);
            }
        }
        opened = true;
    } catch (gnu.io.NoSuchPortException p) {
        return handlePortNotFound(p, portName, log);
    } catch (IOException | TooManyListenersException ex) {
        log.error("Unexpected exception while opening port {} trace follows: ", portName, ex);
        return "Unexpected error while opening port " + portName + ": " + ex;
    }
    // normal operation
    return null;
}
Also used : UnsupportedCommOperationException(gnu.io.UnsupportedCommOperationException) TooManyListenersException(java.util.TooManyListenersException) PortInUseException(gnu.io.PortInUseException) CommPortIdentifier(gnu.io.CommPortIdentifier) UnsupportedCommOperationException(gnu.io.UnsupportedCommOperationException) SerialPortEvent(gnu.io.SerialPortEvent) IOException(java.io.IOException) TooManyListenersException(java.util.TooManyListenersException) PortInUseException(gnu.io.PortInUseException) UnsupportedCommOperationException(gnu.io.UnsupportedCommOperationException) IOException(java.io.IOException)

Example 14 with TooManyListenersException

use of java.util.TooManyListenersException in project guice by google.

the class CheckedProviderTest 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, BindException, SubBindException {
                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 + ", " + BindException.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 + ", " + BindException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(1).getMessage());
        assertEquals(2, errors.size());
    }
}
Also used : BindException(java.net.BindException) CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule) TooManyListenersException(java.util.TooManyListenersException) AccessException(java.rmi.AccessException) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RemoteException(java.rmi.RemoteException)

Example 15 with TooManyListenersException

use of java.util.TooManyListenersException in project Openfire by igniterealtime.

the class SipManager method start.

/**
     * Creates and initializes JAIN SIP objects (factories, stack, listening
     * point and provider). Once this method is called the application is ready
     * to handle (incoming and outgoing) sip messages.
     *
     * @throws CommunicationsException if an axception should occur during the initialization
     *                                 process
     */
public void start() throws CommunicationsException {
    initProperties();
    SIPConfig.setSystemProperties();
    this.sipFactory = SipFactory.getInstance();
    sipFactory.setPathName(sipStackPath);
    try {
        addressFactory = sipFactory.createAddressFactory();
        headerFactory = sipFactory.createHeaderFactory();
        messageFactory = sipFactory.createMessageFactory();
    } catch (PeerUnavailableException ex) {
        Log.error("start", ex);
        throw new CommunicationsException("Could not create factories!", ex);
    }
    try {
        sipStack = sipFactory.createSipStack(System.getProperties());
        ((SipCommRouter) sipStack.getRouter()).setOutboundProxy(SIPConfig.getOutboundProxy());
    } catch (PeerUnavailableException ex) {
        Log.error("start", ex);
        throw new CommunicationsException("Cannot connect!\n" + "Cannot reach proxy.\nCheck your connection." + "(Syntax:<proxy_address:port/transport>)", ex);
    }
    try {
        boolean successfullyBound = false;
        while (!successfullyBound) {
            try {
                publicIpAddress = new InetSocketAddress(localAddress, localPort);
                listeningPoint = sipStack.createListeningPoint(localPort, transport);
            } catch (InvalidArgumentException ex) {
                // choose another port between 1024 and 65000
                localPort = (int) ((65000 - 1024) * Math.random()) + 1024;
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                // Do Nothing
                }
                continue;
            }
            successfullyBound = true;
        }
    } catch (TransportNotSupportedException ex) {
        throw new CommunicationsException("Transport " + transport + " is not suppported by the stack!\n Try specifying another" + " transport in Mais property files.\n", ex);
    }
    try {
        sipProvider = sipStack.createSipProvider(listeningPoint);
    } catch (ObjectInUseException ex) {
        Log.error("start", ex);
        throw new CommunicationsException("Could not create factories!\n", ex);
    }
    try {
        sipProvider.addSipListener(this);
    } catch (TooManyListenersException exc) {
        throw new CommunicationsException("Could not register SipManager as a sip listener!", exc);
    }
    sipSecurityManager.setHeaderFactory(headerFactory);
    sipSecurityManager.setTransactionCreator(sipProvider);
    sipSecurityManager.setSipManCallback(this);
    // Make sure prebuilt headers are nulled so that they get reinited
    // if this is a restart
    contactHeader = null;
    fromHeader = null;
    viaHeaders = null;
    maxForwardsHeader = null;
    isStarted = true;
}
Also used : TooManyListenersException(java.util.TooManyListenersException) InetSocketAddress(java.net.InetSocketAddress) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException) TooManyListenersException(java.util.TooManyListenersException) UnknownHostException(java.net.UnknownHostException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException) ParseException(java.text.ParseException)

Aggregations

TooManyListenersException (java.util.TooManyListenersException)24 PortInUseException (gnu.io.PortInUseException)15 CommPortIdentifier (gnu.io.CommPortIdentifier)14 UnsupportedCommOperationException (gnu.io.UnsupportedCommOperationException)12 IOException (java.io.IOException)11 NoSuchPortException (gnu.io.NoSuchPortException)6 ImmutableList (com.google.common.collect.ImmutableList)4 AbstractModule (com.google.inject.AbstractModule)4 CreationException (com.google.inject.CreationException)4 SerialPortEvent (gnu.io.SerialPortEvent)4 AccessException (java.rmi.AccessException)4 RemoteException (java.rmi.RemoteException)4 List (java.util.List)4 Enumeration (java.util.Enumeration)3 CommPort (gnu.io.CommPort)2 SerialPort (gnu.io.SerialPort)2 SerialPortEventListener (gnu.io.SerialPortEventListener)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 InputStreamReader (java.io.InputStreamReader)2