Search in sources :

Example 1 with TransportException

use of io.transport.sdk.exception.TransportException in project transporter by wang4ever.

the class Configuration method getHostAndPorts.

public List<HostAndPort> getHostAndPorts() {
    if (this.hostAndPorts != null && !this.hostAndPorts.isEmpty())
        return this.hostAndPorts;
    try {
        List<String> hostAndPortTxts = PropertyLoadConfig.getList(PropertyLoadConfig.CLUSTER_ADDR_PKEY);
        for (String handp : hostAndPortTxts) {
            String[] arr = handp.split("\\:");
            this.hostAndPorts.add(new HostAndPort(arr[0], Integer.parseInt(arr[1])));
        }
    } catch (Exception e) {
        throw new TransportException("Server address configuration in illegal format.", e);
    }
    return this.hostAndPorts;
}
Also used : TransportException(io.transport.sdk.exception.TransportException) TransportException(io.transport.sdk.exception.TransportException)

Example 2 with TransportException

use of io.transport.sdk.exception.TransportException in project transporter by wang4ever.

the class TransportChannel method close.

@Override
public void close() throws IOException {
    try {
        if (this.workerGroup != null)
            this.workerGroup.shutdownGracefully();
        if (this.channel != null)
            this.channel.close();
    } catch (Exception e) {
        throw new TransportException(e);
    } finally {
        this.channel = null;
        this.workerGroup = null;
        this.bootstrap = null;
        System.gc();
    }
}
Also used : TransportException(io.transport.sdk.exception.TransportException) IOException(java.io.IOException) TransportException(io.transport.sdk.exception.TransportException)

Example 3 with TransportException

use of io.transport.sdk.exception.TransportException in project transporter by wang4ever.

the class TransportClient method groupcast.

/**
 * 组播发送消息(指定的点对多one-to-many)
 *
 * @param toGroupId
 * @param payload
 * @return 通道对象(可用于控制同步发送方案: groupcast(..).sync())
 * @throws TransportException
 */
public Future<Message> groupcast(String toGroupId, String payload) throws TransportException {
    if (ByteBufs.isEmpty(toGroupId) || ByteBufs.isEmpty(payload))
        throw new TransportException("'toGroupId/payload' is not allowed to be empty.");
    String fromDeviceId = this.config.getDeviceId();
    TransportMessage msg = new TransportMessage(MsgType.TRANSPORT_REQ, fromDeviceId, null, toGroupId, payload);
    return this.execute(msg, true);
}
Also used : TransportException(io.transport.sdk.exception.TransportException) TransportMessage(io.transport.sdk.protocol.message.internal.TransportMessage)

Example 4 with TransportException

use of io.transport.sdk.exception.TransportException in project transporter by wang4ever.

the class TransportClient method registered.

/**
 * 注册客户端连接认证(如:用于Web端ws连接认证)
 *
 * @param expiredSec
 *            过期时间(s)
 * @param deviceIdTokens
 *            多个deviceId
 * @return 通道对象(可用于控制同步发送方案: registered(..).sync())
 * @throws TransportException
 */
public Future<Message> registered(int expiredSec, String... deviceIdTokens) throws TransportException {
    if (!(deviceIdTokens != null && deviceIdTokens.length != 0))
        throw new TransportException("The 'deviceIdTokens' is not allowed to be empty.");
    if (expiredSec <= 0)
        throw new TransportException("'expiredSec' is invalid.");
    DeviceRegistMessage msg = new DeviceRegistMessage();
    msg.setAppId(this.config.getAppId());
    msg.setExpired(expiredSec);
    msg.setClientDeviceIds(Arrays.asList(deviceIdTokens));
    return this.execute(msg, true);
}
Also used : TransportException(io.transport.sdk.exception.TransportException) DeviceRegistMessage(io.transport.sdk.protocol.message.internal.DeviceRegistMessage)

Example 5 with TransportException

use of io.transport.sdk.exception.TransportException in project transporter by wang4ever.

the class TransportClients method groupcast.

/**
 * 组播发送消息(指定的点对多one-to-many)
 *
 * @param toGroupId
 * @param payload
 * @return 通道对象(可用于控制同步发送方案: groupcast(..).sync())
 * @throws TransportException
 */
public Future<Message> groupcast(String toGroupId, String payload) throws TransportException {
    if (StringUtil.isNullOrEmpty(toGroupId) || StringUtil.isNullOrEmpty(payload))
        throw new TransportException("'toGroupId/payload' is not allowed to be empty.");
    String fromDeviceId = Constants.processSerial;
    TransportMessage msg = new TransportMessage(MsgType.TRANSPORT_REQ, fromDeviceId, null, toGroupId, payload);
    return this.execute(msg, true);
}
Also used : TransportException(io.transport.sdk.exception.TransportException) TransportMessage(io.transport.sdk.protocol.message.internal.TransportMessage)

Aggregations

TransportException (io.transport.sdk.exception.TransportException)18 IOException (java.io.IOException)6 TransportMessage (io.transport.sdk.protocol.message.internal.TransportMessage)4 HostAndPort (io.transport.sdk.Configuration.HostAndPort)3 Bootstrap (io.netty.bootstrap.Bootstrap)2 Channel (io.netty.channel.Channel)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 LoggingHandler (io.netty.handler.logging.LoggingHandler)2 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)2 TransportMessageDecoder (io.transport.sdk.protocol.codec.TransportMessageDecoder)2 TransportMessageEncoder (io.transport.sdk.protocol.codec.TransportMessageEncoder)2 DeviceRegistMessage (io.transport.sdk.protocol.message.internal.DeviceRegistMessage)2 TransportAuthenticationException (io.transport.sdk.exception.TransportAuthenticationException)1 TransportInitializeException (io.transport.sdk.exception.TransportInitializeException)1 ArrayList (java.util.ArrayList)1