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

com.byoutline.eventcallback.CallbackConfig Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package com.byoutline.eventcallback;

import java.util.Collections;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.inject.Provider;

/**
 * Callback that stores project wide settings. It is suggested to Inject it into
 * classes that need ability to create callbacks.
 *
 * @author Sebastian Kacprzak  on 26.06.14.
 */
public class CallbackConfig {

    final boolean debug;
    final IBus bus;
    final Provider sessionIdProvider;
    final Map sharedSuccessHandlers;

    /**
     * Creates instance of default config for callbacks. Uses session provider
     * that always return same session, so there will be no difference between
     * sameSessionOnly and multiSessions events. Debug checks will be turned
     * off.
     *
     * @param bus bus on which callback events will be posted.
     */
    public CallbackConfig(@Nonnull IBus bus) {
        this(false, bus);
    }

    /**
     * Creates instance of default config for callbacks. Uses session provider
     * that always return same session, so there will be no difference between
     * sameSessionOnly and multiSessions events.
     *
     * @param debug true if extra checks should be on.
     * @param bus   bus on which callback events will be posted.
     */
    public CallbackConfig(boolean debug, @Nonnull IBus bus) {
        this(debug, bus, new Provider() {

            @Override
            public String get() {
                return "";
            }

        });
    }

    /**
     * Creates instance of default config for callbacks.
     *
     * @param debug             true if extra checks should be on.
     * @param bus               bus on which callback events will be posted.
     * @param sessionIdProvider provides information about current session.
     *                          If same string is returned from two calls it is considered to be same session.
     */
    public CallbackConfig(boolean debug, @Nonnull IBus bus,
                          @Nonnull Provider sessionIdProvider) {
        this(debug, bus, sessionIdProvider, Collections.EMPTY_MAP);
    }

    /**
     * Creates instance of default config for callbacks.
     *
     * @param debug                 true if extra checks should be on.
     * @param bus                   bus on which callback events will be posted.
     * @param sessionIdProvider     provides information about current session.
     *                              If same string is returned from two calls it is considered to be same session.
     * @param sharedSuccessHandlers maps success responses from server with
     *                              {@link SuccessHandler}s so common operation for given result type can
     *                              be handled globally in whole project.
     */
    public CallbackConfig(boolean debug, @Nonnull IBus bus,
                          @Nonnull Provider sessionIdProvider,
                          @Nonnull Map sharedSuccessHandlers) {
        this.debug = debug;
        this.bus = bus;
        this.sessionIdProvider = sessionIdProvider;
        this.sharedSuccessHandlers = sharedSuccessHandlers;
    }

    @Override
    public String toString() {
        return "CallbackConfig{" + "debug=" + debug + ", bus=" + bus + ", sessionIdProvider=" + sessionIdProvider + ", sharedSuccessHandlers=" + sharedSuccessHandlers + '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy