Package io.apigee.trireme.core.internal

Examples of io.apigee.trireme.core.internal.NodeOSException


    public static void kill(Context cx, Scriptable scope, int pid, String signal)
    {
        SpawnedProcess proc = processTable.get(pid);
        if (proc == null) {
            throw Utils.makeError(cx, scope, new NodeOSException(Constants.ESRCH));
        }

        if (signal != null) {
            if (log.isDebugEnabled()) {
                log.debug("Terminating pid {} ({}) with {}", pid, proc, signal);
View Full Code Here


    public void bind(String address, int port)
        throws NodeOSException
    {
        InetSocketAddress bound = new InetSocketAddress(address, port);
        if (bound.isUnresolved()) {
            throw new NodeOSException(Constants.ENOENT);
        }

        boolean success = false;
        try {
            channel = DatagramChannel.open();
            runtime.registerCloseable(channel);
            channel.configureBlocking(false);
            channel.socket().bind(bound);
            selKey = channel.register(runtime.getSelector(), 0,
                             new SelectorHandler() {
                                 @Override
                                 public void selected(SelectionKey key)
                                 {
                                     clientSelected(key);
                                 }
                             });

            success = true;
        } catch (BindException be) {
            log.debug("Error binding: {}", be);
            throw new NodeOSException(Constants.EADDRINUSE);
        } catch (IOException ioe) {
            log.debug("Error binding: {}", ioe);
            throw new NodeOSException(Constants.EIO);
        } finally {
            if (!success) {
                runtime.unregisterCloseable(channel);
                try {
                    channel.close();
View Full Code Here

    {
        InetSocketAddress addr = new InetSocketAddress(host, port);
        NetworkPolicy netPolicy = getNetworkPolicy();
        if ((netPolicy != null) && !netPolicy.allowListening(addr)) {
            log.debug("Address {} not allowed by network policy", addr);
            throw new NodeOSException(Constants.EINVAL);
        }

        QueuedWrite qw = new QueuedWrite(buf, listener, context);
        qw.setAddress(addr);
        offerWrite(qw);
View Full Code Here

        throws NodeOSException
    {
        try {
            channel.socket().setBroadcast(true);
        } catch (IOException e) {
            throw new NodeOSException(Constants.EIO, e);
        }
    }
View Full Code Here

        throws NodeOSException
    {
        try {
            channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);
        } catch (IOException e) {
            throw new NodeOSException(Constants.EIO, e);
        } catch (NoClassDefFoundError cnfe) {
            // This happens on Java 6
            throw new NodeOSException(Constants.ESRCH, "Multicast not available on Java 6");
        }
    }
View Full Code Here

        throws NodeOSException
    {
        try {
            channel.setOption(StandardSocketOptions.IP_MULTICAST_LOOP, on);
        } catch (IOException e) {
            throw new NodeOSException(Constants.EIO, e);
        } catch (NoClassDefFoundError cnfe) {
            // This happens on Java 6
            throw new NodeOSException(Constants.ESRCH, "Multicast not available on Java 6");
        }
    }
View Full Code Here

    public void bind(String address, int port)
        throws NodeOSException
    {
        boundAddress = new InetSocketAddress(address, port);
        if (boundAddress.isUnresolved()) {
            throw new NodeOSException(Constants.ENOENT);
        }
    }
View Full Code Here

    public void listen(int backlog, NetworkHandleListener listener, Object context)
        throws NodeOSException
    {
        if (boundAddress == null) {
            throw new NodeOSException(Constants.EINVAL);
        }
        NetworkPolicy netPolicy = getNetworkPolicy();
        if ((netPolicy != null) && !netPolicy.allowListening(boundAddress)) {
            log.debug("Address {} not allowed by network policy", boundAddress);
            throw new NodeOSException(Constants.EINVAL);
        }

        this.listener = listener;
        this.listenerCtx = context;
        if (log.isDebugEnabled()) {
            log.debug("Server listening on {} with backlog {}",
                      boundAddress, backlog);
        }

        boolean success = false;
        try {
            svrChannel = ServerSocketChannel.open();
            runtime.registerCloseable(svrChannel);
            svrChannel.configureBlocking(false);
            svrChannel.socket().setReuseAddress(true);
            svrChannel.socket().bind(boundAddress, backlog);
            svrChannel.register(runtime.getSelector(), SelectionKey.OP_ACCEPT,
                                new SelectorHandler()
                                {
                                    @Override
                                    public void selected(SelectionKey key)
                                    {
                                        serverSelected(key);
                                    }
                                });
            success = true;

        } catch (BindException be) {
            log.debug("Error listening: {}", be);
            throw new NodeOSException(Constants.EADDRINUSE);
        } catch (IOException ioe) {
            log.debug("Error listening: {}", ioe);
            throw new NodeOSException(Constants.EIO);
        } finally {
            if (!success && (svrChannel != null)) {
                runtime.unregisterCloseable(svrChannel);
                try {
                    svrChannel.close();
View Full Code Here

        try {
            InetSocketAddress targetAddress = new InetSocketAddress(host, port);
            NetworkPolicy netPolicy = getNetworkPolicy();
            if ((netPolicy != null) && !netPolicy.allowConnection(targetAddress)) {
                log.debug("Disallowed connection to {} due to network policy", targetAddress);
                throw new NodeOSException(Constants.EINVAL);
            }

            if (log.isDebugEnabled()) {
                log.debug("Client connecting to {}:{}", host, port);
            }
            if (boundAddress == null) {
                newChannel = SocketChannel.open();
            } else {
                newChannel = SocketChannel.open(boundAddress);
            }

            runtime.registerCloseable(newChannel);
            clientChannel = newChannel;
            clientInit();
            this.listener = listener;
            this.listenerCtx = context;
            newChannel.connect(targetAddress);
            selKey = newChannel.register(runtime.getSelector(),
                                                    SelectionKey.OP_CONNECT,
                                                    new SelectorHandler()
                                                    {
                                                        @Override
                                                        public void selected(SelectionKey key)
                                                        {
                                                            clientSelected(key);
                                                        }
                                                    });

            success = true;

        } catch (IOException ioe) {
            log.debug("Error on connect: {}", ioe);
            throw new NodeOSException(Constants.EIO);
        } finally {
            if (!success && (newChannel != null)) {
                runtime.unregisterCloseable(newChannel);
                try {
                    newChannel.close();
View Full Code Here

        if (clientChannel != null) {
            try {
                clientChannel.socket().setTcpNoDelay(nd);
            } catch (SocketException e) {
                log.error("Error setting TCP no delay on {}: {}", this, e);
                throw new NodeOSException(Constants.EIO);
            }
        }
    }
View Full Code Here

TOP

Related Classes of io.apigee.trireme.core.internal.NodeOSException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.