Search in sources :

Example 1 with IProvide

use of logisticspipes.interfaces.routing.IProvide in project LogisticsPipes by RS485.

the class RequestTreeNode method getProviders.

private static List<Pair<IProvide, List<IFilter>>> getProviders(IRouter destination, IResource item) {
    // get all the routers
    BitSet routersIndex = ServerRouter.getRoutersInterestedIn(item);
    // get the routing table
    List<ExitRoute> validSources = new ArrayList<>();
    for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
        IRouter r = SimpleServiceLocator.routerManager.getServerRouter(i);
        if (r.isCacheInvalid()) {
            // Skip Routers without a valid pipe
            continue;
        }
        List<ExitRoute> e = destination.getDistanceTo(r);
        if (e != null) {
            validSources.addAll(e);
        }
    }
    // closer providers are good
    validSources.sort(new workWeightedSorter(1.0));
    List<Pair<IProvide, List<IFilter>>> providers = new LinkedList<>();
    validSources.stream().filter(r -> r.containsFlag(PipeRoutingConnectionType.canRequestFrom)).forEach(r -> {
        CoreRoutedPipe pipe = r.destination.getPipe();
        if (pipe instanceof IProvide) {
            List<IFilter> list = new LinkedList<>(r.filters);
            providers.add(new Pair<>((IProvide) pipe, list));
        }
    });
    return providers;
}
Also used : SortedSet(java.util.SortedSet) Getter(lombok.Getter) IRouter(logisticspipes.routing.IRouter) IOrderInfoProvider(logisticspipes.routing.order.IOrderInfoProvider) PriorityQueue(java.util.PriorityQueue) IProvide(logisticspipes.interfaces.routing.IProvide) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) ActiveRequestType(logisticspipes.request.RequestTree.ActiveRequestType) RequestTree.workWeightedSorter(logisticspipes.request.RequestTree.workWeightedSorter) LinkedList(java.util.LinkedList) EnumSet(java.util.EnumSet) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) Iterator(java.util.Iterator) LogisticsOrderManager(logisticspipes.routing.order.LogisticsOrderManager) Set(java.util.Set) ExitRoute(logisticspipes.routing.ExitRoute) ServerRouter(logisticspipes.routing.ServerRouter) IResource(logisticspipes.request.resources.IResource) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) BitSet(java.util.BitSet) Collections(java.util.Collections) ICraft(logisticspipes.interfaces.routing.ICraft) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) LinkedList(java.util.LinkedList) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) RequestTree.workWeightedSorter(logisticspipes.request.RequestTree.workWeightedSorter) ExitRoute(logisticspipes.routing.ExitRoute) IProvide(logisticspipes.interfaces.routing.IProvide) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 PriorityQueue (java.util.PriorityQueue)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)1 ICraft (logisticspipes.interfaces.routing.ICraft)1 IFilter (logisticspipes.interfaces.routing.IFilter)1 IProvide (logisticspipes.interfaces.routing.IProvide)1 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)1