/** * Attempts to match buyer and sellers. This implementations uses a very simple approach: For each * buyer, all sellers of the resource are searched, and each of them either sells everything it * has, or up to the amount needed. No attempt is done to match the best buyer and seller and * reduce the number of operations. */ @Override protected void matchBothEnds() { LOGGER.info("ACA ENTRO UNO"); for (ResourceStock buyer : buying) { LOGGER.info("ACA ENTRO DOS"); for (ResourceStock seller : selling) { if (buyer.resource().equals(seller.resource())) { // LOGGER.info("Se buscan:"+buying.count(buyer)+"Tengo en seller:"+selling.count(seller)); LOGGER.info(buyer.name() + " Encontre algo en la cola interna"); Integer resp = transfer(buyer, seller); if (resp != 0) { LOGGER.info( "ENCONTRADO EN SELLING, SE TRANSFIRIERON:" + buyer.name() + "<==" + resp + " de " + buyer.resource() + "<==" + seller.name()); } } } if (buying.count(buyer) != 0) { /* Me fijo si lo tenia de una transaccion anterior */ for (Resource outResource : externalRepository) { if (buyer.resource().equals(outResource)) { LOGGER.info(buyer.name() + "ENCONTRADO EN LA COLA EXTERNA."); Integer resp = transferResource(buyer, outResource); if (resp != 0) { LOGGER.info( "SE TRANSFIRIERON:" + buyer.name() + "<====" + resp + " de " + buyer.resource()); } } } /* * Debo pedir afuera mi recurso, el handler de la respuesta es * el encargado de cargarmelo */ if (buying.count(buyer) != 0) { LOGGER.info( buyer.name() + " SOLICITUD RECURSOS:" + buying.count(buyer) + " DE " + buyer.resource()); this.myMarketManager.requestResources(buying.count(buyer), buyer.resource()); } } } }