Example usage for io.netty.channel.unix DomainSocketAddress DomainSocketAddress

List of usage examples for io.netty.channel.unix DomainSocketAddress DomainSocketAddress

Introduction

In this page you can find the example usage for io.netty.channel.unix DomainSocketAddress DomainSocketAddress.

Prototype

public DomainSocketAddress(File file) 

Source Link

Usage

From source file:alluxio.util.network.NetworkAddressUtils.java

License:Apache License

/**
 * Extracts dataPort socket address from Alluxio representation of network address.
 *
 * @param netAddress the input network address representation
 * @return the socket address/*from   w  ww  .  j ava2  s .  co  m*/
 */
public static SocketAddress getDataPortSocketAddress(WorkerNetAddress netAddress) {
    SocketAddress address;
    if (NettyUtils.isDomainSocketSupported(netAddress)) {
        address = new DomainSocketAddress(netAddress.getDomainSocketPath());
    } else {
        String host = netAddress.getHost();
        int port = netAddress.getDataPort();
        address = new InetSocketAddress(host, port);
    }
    return address;
}

From source file:alluxio.worker.AlluxioWorkerProcess.java

License:Apache License

/**
 * Creates a new instance of {@link AlluxioWorkerProcess}.
 */// w w w .  j  a v a 2 s .  c o m
AlluxioWorkerProcess() {
    try {
        mStartTimeMs = System.currentTimeMillis();
        mUfsManager = new WorkerUfsManager();
        mRegistry = new WorkerRegistry();
        List<Callable<Void>> callables = new ArrayList<>();
        for (final WorkerFactory factory : ServiceUtils.getWorkerServiceLoader()) {
            callables.add(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    if (factory.isEnabled()) {
                        factory.create(mRegistry, mUfsManager);
                    }
                    return null;
                }
            });
        }
        CommonUtils.invokeAll(callables, 10, TimeUnit.SECONDS);

        // Setup web server
        mWebServer = new WorkerWebServer(NetworkAddressUtils.getBindAddress(ServiceType.WORKER_WEB), this,
                mRegistry.get(BlockWorker.class), NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC),
                mStartTimeMs);

        // Setup Thrift server
        mTransportProvider = TransportProvider.Factory.create();
        mThriftServerSocket = createThriftServerSocket();
        int rpcPort = NetworkAddressUtils.getThriftPort(mThriftServerSocket);
        String rpcHost = NetworkAddressUtils.getThriftSocket(mThriftServerSocket).getInetAddress()
                .getHostAddress();
        mRpcAddress = new InetSocketAddress(rpcHost, rpcPort);
        mThriftServer = createThriftServer();

        // Setup Data server
        mDataServer = DataServer.Factory.create(NetworkAddressUtils.getBindAddress(ServiceType.WORKER_DATA),
                this);

        if (isDomainSocketEnabled()) {
            String domainSocketPath = Configuration.get(PropertyKey.WORKER_DATA_SERVER_DOMAIN_SOCKET_ADDRESS);
            LOG.info("Domain socket data server is enabled at {}.", domainSocketPath);
            mDomainSocketDataServer = DataServer.Factory.create(new DomainSocketAddress(domainSocketPath),
                    this);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:at.yawk.dbus.protocol.DbusConnector.java

public DbusChannel connect(DbusAddress address) throws Exception {
    log.info("Connecting to dbus server at {}", address);

    switch (address.getProtocol()) {
    case "unix":
        if (address.hasProperty("path")) {
            return connect(new DomainSocketAddress(address.getProperty("path")));
        } else if (address.hasProperty("abstract")) {
            return connect(new DomainSocketAddress('\0' + address.getProperty("abstract")));
        } else {/*from  w ww  . ja va2 s .  co m*/
            throw new IllegalArgumentException("Neither path nor abstract given in dbus url");
        }
    case "tcp":
        String host = address.getProperty("host");
        int port = Integer.parseInt(address.getProperty("port"));
        return connect(new InetSocketAddress(host, port));
    default:
        throw new UnsupportedOperationException("Unsupported protocol " + address.getProtocol());
    }
}

From source file:at.yawk.dbus.protocol.DbusConnectorTest.java

@Test(enabled = false)
public void testServer() throws Exception {
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.channel(EpollServerDomainSocketChannel.class);
    bootstrap.group(new EpollEventLoopGroup());
    bootstrap.childHandler(new ChannelInitializer<Channel>() {
        @Override//from   w  ww  .j a v a 2  s .  c o m
        protected void initChannel(Channel ch) throws Exception {

            ch.pipeline().addLast(new CommandCodec()).addLast(new ChannelDuplexHandler() {
                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                    if (msg instanceof NegotiateUnixFd) {
                        ch.writeAndFlush(new Error("error"));
                    }

                    if (msg instanceof Begin) {
                        ch.pipeline().addLast(new LoggingInboundAdapter())
                                .addLast(new DbusMainProtocol(new MessageConsumer() {
                                    @Override
                                    public boolean requireAccept(MessageHeader header) {
                                        return true;
                                    }

                                    @Override
                                    public void accept(DbusMessage message) {
                                        DbusMessage response = new DbusMessage();

                                        MessageHeader header = new MessageHeader();
                                        header.setMessageType(MessageType.ERROR);
                                        header.addHeader(HeaderField.REPLY_SERIAL,
                                                BasicObject.createUint32(message.getHeader().getSerial()));
                                        //header.addHeader(HeaderField.SIGNATURE, SignatureObject.create(
                                        //        Collections.singletonList(BasicType.VARIANT)));
                                        header.addHeader(HeaderField.ERROR_NAME,
                                                BasicObject.createString("Error"));
                                        response.setHeader(header);

                                        MessageBody body = new MessageBody();
                                        //body.add(VariantObject.create(BasicObject.createString("testing!")));
                                        response.setBody(body);

                                        ch.writeAndFlush(response);
                                    }
                                }));
                        ch.pipeline().remove((Class) getClass());
                        ch.pipeline().remove(CommandCodec.class);
                    }
                }
            });
            ch.writeAndFlush(new Ok(UUID.randomUUID()));
        }
    });
    bootstrap.bind(new DomainSocketAddress(new File("test")));

    try {
        DbusUtil.callCommand(("dbus-send --address=unix:path=" + new File(".").getAbsolutePath()
                + "/test --dest=org.freedesktop.UPower --print-reply "
                + "/org/freedesktop/UPower/devices/DisplayDevice org.freedesktop.DBus.Properties.Get string:org"
                + ".freedesktop.UPower.Device string:State").split(" "));
    } catch (Exception e) {
        e.printStackTrace();
    }
    TimeUnit.DAYS.sleep(1);
}

From source file:com.google.devtools.build.lib.remote.SimpleBlobStoreFactory.java

License:Open Source License

public static SimpleBlobStore createRest(RemoteOptions options, Credentials creds) {
    try {//from  w ww .  j av a2 s. c o m
        URI uri = URI.create(options.remoteHttpCache);
        int timeoutMillis = (int) TimeUnit.SECONDS.toMillis(options.remoteTimeout);

        if (options.remoteCacheProxy != null) {
            if (options.remoteCacheProxy.startsWith("unix:")) {
                return HttpBlobStore.create(
                        new DomainSocketAddress(options.remoteCacheProxy.replaceFirst("^unix:", "")), uri,
                        timeoutMillis, options.remoteMaxConnections, creds);
            } else {
                throw new Exception("Remote cache proxy unsupported: " + options.remoteCacheProxy);
            }
        } else {
            return HttpBlobStore.create(uri, timeoutMillis, options.remoteMaxConnections, creds);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:de.dentrassi.varlink.internal.ConnectionImpl.java

License:Open Source License

ConnectionImpl(final EventLoopGroup group, final Path socket) {
    Objects.requireNonNull(group);
    Objects.requireNonNull(socket);

    this.group = group;
    this.address = new DomainSocketAddress(socket.toFile());
}

From source file:io.grpc.benchmarks.Utils.java

License:Apache License

/**
 * Parse a {@link SocketAddress} from the given string.
 *///from  ww w  .j a  v a2 s .  c  o m
public static SocketAddress parseSocketAddress(String value) {
    if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
        // Unix Domain Socket address.
        // Create the underlying file for the Unix Domain Socket.
        String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
        File file = new File(filePath);
        if (!file.isAbsolute()) {
            throw new IllegalArgumentException("File path must be absolute: " + filePath);
        }
        try {
            if (file.createNewFile()) {
                // If this application created the file, delete it when the application exits.
                file.deleteOnExit();
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        // Create the SocketAddress referencing the file.
        return new DomainSocketAddress(file);
    } else {
        // Standard TCP/IP address.
        String[] parts = value.split(":", 2);
        if (parts.length < 2) {
            throw new IllegalArgumentException(
                    "Address must be a unix:// path or be in the form host:port. Got: " + value);
        }
        String host = parts[0];
        int port = Integer.parseInt(parts[1]);
        return new InetSocketAddress(host, port);
    }
}

From source file:io.grpc.services.BinaryLogTest.java

License:Open Source License

@Test
public void socketToProto_unix() throws Exception {
    String path = "/some/path";
    DomainSocketAddress socketAddress = new DomainSocketAddress(path);
    assertEquals(//  w  w w .j  a  v a  2 s.  c om
            Peer.newBuilder().setPeerType(Peer.PeerType.PEER_UNIX)
                    .setPeer(ByteString.copyFrom(path.getBytes(US_ASCII))).build(),
            BinaryLog.socketToProto(socketAddress));
}

From source file:io.grpc.services.BinlogHelperTest.java

License:Apache License

@Test
public void socketToProto_unix() throws Exception {
    String path = "/some/path";
    DomainSocketAddress socketAddress = new DomainSocketAddress(path);
    assertEquals(Address.newBuilder().setType(Type.TYPE_UNIX).setAddress("/some/path").build(),
            BinlogHelper.socketToProto(socketAddress));
}

From source file:io.grpc.services.ChannelzProtoUtilTest.java

License:Apache License

@Test
public void toAddress_uds() throws Exception {
    String path = "/tmp/foo";
    DomainSocketAddress uds = new DomainSocketAddress(path);
    assertEquals(Address.newBuilder().setUdsAddress(UdsAddress.newBuilder().setFilename(path)).build(),
            ChannelzProtoUtil.toAddress(uds));
}