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

graphql.servlet.internal.ApolloSubscriptionProtocolFactory Maven / Gradle / Ivy

There is a newer version: 16.0.0
Show newest version
package graphql.servlet.internal;

import graphql.servlet.ApolloSubscriptionConnectionListener;

/**
 * @author Andrew Potter
 */
public class ApolloSubscriptionProtocolFactory extends SubscriptionProtocolFactory {
    private final SubscriptionHandlerInput subscriptionHandlerInput;
    private final SubscriptionSender subscriptionSender;
    private final ApolloSubscriptionKeepAliveRunner keepAliveRunner;
    private final ApolloSubscriptionConnectionListener connectionListener;

    public ApolloSubscriptionProtocolFactory(SubscriptionHandlerInput subscriptionHandlerInput) {
        super("graphql-ws");
        this.subscriptionHandlerInput = subscriptionHandlerInput;
        this.connectionListener = subscriptionHandlerInput.getSubscriptionConnectionListener()
                .filter(ApolloSubscriptionConnectionListener.class::isInstance)
                .map(ApolloSubscriptionConnectionListener.class::cast)
                .orElse(new ApolloSubscriptionConnectionListener() {});
        subscriptionSender =
            new SubscriptionSender(subscriptionHandlerInput.getGraphQLObjectMapper().getJacksonMapper());
        keepAliveRunner = new ApolloSubscriptionKeepAliveRunner(subscriptionSender, connectionListener.getKeepAliveInterval());
    }

    @Override
    public SubscriptionProtocolHandler createHandler() {
        return new ApolloSubscriptionProtocolHandler(subscriptionHandlerInput, connectionListener, subscriptionSender, keepAliveRunner);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy