io.gravitee.exchange.api.channel.Channel Maven / Gradle / Ivy
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.exchange.api.channel;
import io.gravitee.exchange.api.channel.exception.ChannelClosedException;
import io.gravitee.exchange.api.channel.exception.ChannelInitializationException;
import io.gravitee.exchange.api.channel.exception.ChannelNoReplyException;
import io.gravitee.exchange.api.channel.exception.ChannelTimeoutException;
import io.gravitee.exchange.api.channel.exception.ChannelUnknownCommandException;
import io.gravitee.exchange.api.command.Command;
import io.gravitee.exchange.api.command.CommandAdapter;
import io.gravitee.exchange.api.command.CommandHandler;
import io.gravitee.exchange.api.command.Reply;
import io.gravitee.exchange.api.command.ReplyAdapter;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Single;
import java.util.List;
/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public interface Channel {
/**
* Get the unique id of this channel.
*
* @return the id of the channel.
*/
String id();
/**
* Get the target id the channel is opened for.
*
* @return target id.
*/
String targetId();
/**
* Must be called to initialize channel connectivity
*
* @return returns a {@code Completable} instance that completes in case of success or a {@link ChannelInitializationException} is emitted
*/
Completable initialize();
/**
* Must be called to properly close channel
*
* @return returns a {@code Completable} instance that completes in case of success or a {@link ChannelClosedException} is emitted
*/
Completable close();
/**
* Return true
is the current channel is active and ready to receive new commands, false
otherwise.
*
* @return status of the channel.
*/
boolean isActive();
/**
* Return true
if the current channel has pending commands waiting for reply, false
otherwise.
*
* @return status of the channel.
*/
boolean hasPendingCommands();
/**
* Send the actual commands to the current channel. In case of error, different exception could be returned:
*
* - if the channel is inactive {@link ChannelInitializationException} is signaled
* - if no reply has been received before the timeout is reached {@link ChannelTimeoutException} is signaled
* - if command is unknown by the receiver {@link ChannelUnknownCommandException} is signaled
* - if the receiver cannot reply {@link ChannelNoReplyException} is signaled
*
* @return a {@code Single} with the {@code Reply} of the command
*/
, R extends Reply>> Single send(final C command);
/**
* Add customs {@link CommandHandler} to this channel
*/
void addCommandHandlers(final List, ? extends Reply>>> commandHandlers);
/**
* Add customs {@link CommandAdapter} to this channel
*/
void addCommandAdapters(final List, ? extends Command>, ? extends Reply>>> commandAdapters);
/**
* Add customs {@link ReplyAdapter} to this channel
*/
void addReplyAdapters(final List, ? extends Reply>>> replyAdapters);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy