services.DatafeedEventsService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of symphony-api-client-java Show documentation
Show all versions of symphony-api-client-java Show documentation
Symphony API Client provided by Symphony Platform Solutions team
package services;
import authentication.SymBotAuth;
import clients.SymBotClient;
import clients.symphony.api.DatafeedClient;
import exceptions.APIClientErrorException;
import exceptions.SymClientException;
import exceptions.UnauthorizedException;
import listeners.ConnectionListener;
import listeners.IMListener;
import listeners.RoomListener;
import model.DatafeedEvent;
import model.DatafeedEventsList;
import model.events.MessageSent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import utils.SymMessageParser;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class DatafeedEventsService {
private final Logger logger = LoggerFactory.getLogger(DatafeedEventsService.class);
private SymBotClient botClient;
private DatafeedClient datafeedClient;
private List roomListeners;
private List IMListeners;
private List connectionListeners;
private String datafeedId;
private ExecutorService pool;
private AtomicBoolean stop = new AtomicBoolean();
public DatafeedEventsService(SymBotClient client) {
this.botClient = client;
roomListeners = new ArrayList<>();
IMListeners = new ArrayList<>();
connectionListeners = new ArrayList<>();
datafeedClient = this.botClient.getDatafeedClient();
datafeedId = datafeedClient.createDatafeed();
readDatafeed();
stop.set(false);
}
public void addRoomListener(RoomListener listener){
roomListeners.add(listener);
}
public void removeRoomListener(RoomListener listener){
roomListeners.remove(listener);
}
public void addIMListener(IMListener listener){
IMListeners.add(listener);
}
public void removeIMListener(IMListener listener){
IMListeners.remove(listener);
}
public void addConnectionsListener(ConnectionListener listener){
connectionListeners.add(listener);
}
public void removeConnectionsListener(ConnectionListener listener){
connectionListeners.remove(listener);
}
public void readDatafeed(){
if( pool!=null) {
pool.shutdown();
}
pool = Executors.newFixedThreadPool(5);
CompletableFuture.supplyAsync(() -> {
while(!stop.get()) {
CompletableFuture
© 2015 - 2025 Weber Informatics LLC | Privacy Policy