use of logisticspipes.proxy.computers.objects.CCSinkResponder in project LogisticsPipes by RS485.
the class ModuleCCBasedQuickSort method handleSinkResponses.
private void handleSinkResponses(IInventoryUtil invUtil) {
boolean changed = false;
Iterator<Entry<Integer, Pair<Integer, List<CCSinkResponder>>>> iter = sinkResponses.entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer, Pair<Integer, List<CCSinkResponder>>> pair = iter.next();
pair.getValue().setValue1(pair.getValue().getValue1() + 1);
boolean canBeHandled = true;
for (CCSinkResponder response : pair.getValue().getValue2()) {
if (!response.isDone()) {
canBeHandled = false;
break;
}
}
if (canBeHandled || pair.getValue().getValue1() > timeout) {
// skip entry, if slot is not in the inventory (too high).
boolean slotInInventory = pair.getKey() < invUtil.getSizeInventory();
if (slotInInventory && handle(invUtil, pair.getKey(), pair.getValue().getValue2())) {
stalled = false;
lastSuceededStack = pair.getKey();
}
iter.remove();
changed = true;
}
}
if (changed) {
checkSize();
}
}
use of logisticspipes.proxy.computers.objects.CCSinkResponder in project LogisticsPipes by RS485.
the class ModuleCCBasedQuickSort method createSinkMessage.
private void createSinkMessage(int slot, ItemIdentifierStack stack) {
List<CCSinkResponder> respones = new ArrayList<>();
IRouter sourceRouter = _service.getRouter();
if (sourceRouter == null) {
return;
}
// get only pipes with generic interest
BitSet routersIndex = ServerRouter.getRoutersInterestedIn((ItemIdentifier) null);
// get the routing table
List<ExitRoute> validDestinations = new ArrayList<>();
for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
IRouter r = SimpleServiceLocator.routerManager.getRouterUnsafe(i, false);
List<ExitRoute> exits = sourceRouter.getDistanceTo(r);
if (exits != null) {
validDestinations.addAll(exits.stream().filter(e -> e.containsFlag(PipeRoutingConnectionType.canRouteTo)).collect(Collectors.toList()));
}
}
Collections.sort(validDestinations);
outer: for (ExitRoute candidateRouter : validDestinations) {
if (candidateRouter.destination.getId().equals(sourceRouter.getId())) {
continue;
}
for (IFilter filter : candidateRouter.filters) {
if (filter.blockRouting() || (filter.isBlocked() == filter.isFilteredItem(stack.getItem()))) {
continue outer;
}
}
if (candidateRouter.destination != null && candidateRouter.destination.getLogisticsModule() != null) {
respones.addAll(candidateRouter.destination.getLogisticsModule().queueCCSinkEvent(stack));
}
}
sinkResponses.put(slot, new Pair<>(0, respones));
}
use of logisticspipes.proxy.computers.objects.CCSinkResponder in project LogisticsPipes by RS485.
the class ModuleCCBasedItemSink method queueCCSinkEvent.
@Override
public List<CCSinkResponder> queueCCSinkEvent(ItemIdentifierStack item) {
CCSinkResponder resonse = new CCSinkResponder(item, _service.getSourceID(), eventQueuer);
eventQueuer.queueEvent("ItemSink", new Object[] { SimpleServiceLocator.ccProxy.getAnswer(resonse) });
return new OneList<>(resonse);
}
use of logisticspipes.proxy.computers.objects.CCSinkResponder in project LogisticsPipes by RS485.
the class ModuleCCBasedQuickSort method handle.
private boolean handle(IInventoryUtil invUtil, int slot, List<CCSinkResponder> list) {
if (list.isEmpty()) {
return false;
}
ItemIdentifier ident = list.get(0).getStack().getItem();
ItemStack stack = invUtil.getStackInSlot(slot);
if (stack == null || !ItemIdentifier.get(stack).equals(ident)) {
return false;
}
final IRouter source = _service.getRouter();
List<Triplet<Integer, Double, CCSinkResponder>> posibilities = new ArrayList<>();
for (CCSinkResponder sink : list) {
if (!sink.isDone()) {
continue;
}
if (sink.getCanSink() < 1) {
continue;
}
IRouter r = SimpleServiceLocator.routerManager.getRouter(sink.getRouterId());
if (r == null) {
continue;
}
List<ExitRoute> ways = source.getDistanceTo(r);
double minDistance = Double.MAX_VALUE;
outer: for (ExitRoute route : ways) {
for (IFilter filter : route.filters) {
if (filter.blockRouting() || filter.isFilteredItem(ident) == filter.isBlocked()) {
continue outer;
}
}
minDistance = Math.min(route.distanceToDestination, minDistance);
}
if (minDistance != Integer.MAX_VALUE) {
posibilities.add(new Triplet<>(sink.getPriority(), minDistance, sink));
}
}
if (posibilities.isEmpty()) {
return false;
}
Collections.sort(posibilities, (o1, o2) -> {
int c = o2.getValue1() - o1.getValue1();
if (c != 0) {
return c;
}
double e = o1.getValue2() - o2.getValue2();
return e < 0 ? -1 : 1;
});
boolean sended = false;
for (Triplet<Integer, Double, CCSinkResponder> triple : posibilities) {
CCSinkResponder sink = triple.getValue3();
if (sink.getCanSink() < 0) {
continue;
}
stack = invUtil.getStackInSlot(slot);
if (stack == null || stack.stackSize <= 0) {
continue;
}
int amount = Math.min(stack.stackSize, sink.getCanSink());
ItemStack extracted = invUtil.decrStackSize(slot, amount);
_service.sendStack(extracted, sink.getRouterId(), ItemSendMode.Fast, null);
sended = true;
}
return sended;
}
Aggregations