All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.com.graphql_java_generator.client.SubscriptionClientReactiveImpl Maven / Gradle / Ivy

There is a newer version: 1.18
Show newest version
/**
 * 
 */
package com.graphql_java_generator.client;

import org.springframework.web.reactive.socket.CloseStatus;
import org.springframework.web.reactive.socket.WebSocketSession;

import com.graphql_java_generator.exception.GraphQLRequestExecutionException;

import reactor.core.Disposable;
import reactor.core.publisher.Flux;

/**
 * Default implementation for the {@link SubscriptionClient} interface.
 * 
 * @author etienne-sf
 */
public class SubscriptionClientReactiveImpl implements SubscriptionClient {

	/**
	 * The {@link Disposable} That allows to close the underlying {@link Flux}, that receive the subscription
	 * notifications
	 */
	Disposable disposable;

	/** The connected {@link WebSocketSession} */
	WebSocketSession session;

	/**
	 * 
	 * @param disposable
	 *            The {@link Disposable} That allows to close the underlying {@link Flux}, that receive the subscription
	 *            notifications
	 * @param session
	 *            The connected {@link WebSocketSession}
	 */
	public SubscriptionClientReactiveImpl(Disposable disposable, WebSocketSession session) {
		this.disposable = disposable;
		this.session = session;
	}

	@Override
	public void unsubscribe() throws GraphQLRequestExecutionException {
		try {
			if (session != null) {
				session.close(CloseStatus.NORMAL);
				session = null;
			}
			if (disposable != null) {
				disposable.dispose();
				disposable = null;
			}
		} catch (Exception e) {
			throw new GraphQLRequestExecutionException(e.getMessage(), e);
		}
	}

	@Override
	public WebSocketSession getSession() {
		return session;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy