org.rribbit.util.RRiBbitUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rribbit Show documentation
Show all versions of rribbit Show documentation
RRiBbit is an Open Source Java application framework that eliminates dependencies and simplifies code structure. It can be used as an Eventbus, but improves upon
this by being compatible with existing code and allowing bidirectional communication between components. It also supports Remoting, so that you can use Eventbuses that
run on other machines, complete with failover, loadbalancing and SSL/TLS support.
The newest version!
/*
* Copyright (C) 2012-2024 RRiBbit.org
*
* 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
*
* https://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 org.rribbit.util;
import org.rribbit.DefaultRequestResponseBus;
import org.rribbit.RRB;
import org.rribbit.RequestResponseBus;
import org.rribbit.creation.ListenerObjectCreator;
import org.rribbit.dispatching.LocalRequestDispatcher;
import org.rribbit.dispatching.RequestDispatcher;
import org.rribbit.execution.ListenerObjectExecutor;
import org.rribbit.execution.MultiThreadedListenerObjectExecutor;
import org.rribbit.processing.LocalRequestProcessor;
import org.rribbit.retrieval.CachedListenerObjectRetriever;
import org.rribbit.retrieval.ListenerObjectRetriever;
/**
* This class simplifies setting up RRiBbit for use.
*
* @author G.J. Schouten
*
*/
public final class RRiBbitUtil {
/**
* This class should not be instantiated.
*/
private RRiBbitUtil() {}
/**
* Takes care of setting up the various objects needed to use RRiBbit locally. You have to specify the {@link ListenerObjectCreator}, because it's impossible for
* {@link RRiBbitUtil} to guess a sensible default here, but all of the other objects will be instantiated by {@link RRiBbitUtil}. If you want different objects
* than the defaults, or if you want to use RRiBbit remotely over the network, you will have to wire them together yourself.
*
* The classes that are chosen:
*
* - {@link CachedListenerObjectRetriever}
* - {@link MultiThreadedListenerObjectExecutor}
* - {@link LocalRequestProcessor}
* - {@link LocalRequestDispatcher}
* - {@link DefaultRequestResponseBus}
*
*
* @param listenerObjectCreator The {@link ListenerObjectCreator} to use
* @param setInRRB Whether or not to set the created {@link RequestResponseBus} in {@link RRB}.
* @return A {@link RequestResponseBus} ready for local use.
*/
public static RequestResponseBus createRequestResponseBusForLocalUse(ListenerObjectCreator listenerObjectCreator, boolean setInRRB) {
ListenerObjectRetriever listenerObjectRetriever = new CachedListenerObjectRetriever(listenerObjectCreator);
ListenerObjectExecutor listenerObjectExecutor = new MultiThreadedListenerObjectExecutor();
LocalRequestProcessor localRequestProcessor = new LocalRequestProcessor(listenerObjectRetriever, listenerObjectExecutor);
RequestDispatcher requestDispatcher = new LocalRequestDispatcher(localRequestProcessor);
RequestResponseBus requestResponseBus = new DefaultRequestResponseBus(requestDispatcher);
if(setInRRB) {
RRB.setRequestResponseBus(requestResponseBus);
}
return requestResponseBus;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy