Ejemplo n.º 1
0
  public void processFollowings() {
    while (true) {
      QueueingConsumer.Delivery delivery;
      try {
        delivery = consumer.nextDelivery();
        String message = new String(delivery.getBody());
        Long tag = delivery.getEnvelope().getDeliveryTag();

        String[] split = message.split(" ");
        Long followerVkId = Long.valueOf(split[0]);
        Long followingVkId = Long.valueOf(split[1]);

        Follower follower = dbService.getFollowerByVkId(followerVkId);
        Following following = follower.getFollowingByVkId(followingVkId);

        refreshFollowing(follower, following);

        channel.basicAck(tag, false);
        System.out.println("Ok");
      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 2
0
 @SuppressWarnings(value = "unchecked")
 private <
         TypeOfSnapshot extends Snapshot,
         Refresher extends SnapshotBuilder,
         TypeOfEvent extends Event,
         EventEntity>
     void Process(
         Refresher refresher,
         Follower follower,
         Following following,
         FollowingEventTypes followingEventTypes,
         FollowerEvents followerEvents,
         List<Snapshot> snapshots,
         int i,
         Class<EventEntity> eventEntityClass,
         Class<TypeOfSnapshot> typeOfSnapshotClass,
         Class<TypeOfEvent> typeOfEventClass,
         SnapshotDifference snapshotDifference,
         EventType eventType) {
   TypeOfSnapshot snapshot = (TypeOfSnapshot) refresher.build(following, follower);
   if (snapshots.size() < followingEventTypes.getEventTypes().size()) {
     snapshot.getList().forEach(a -> dbService.save((EventEntity) a, eventEntityClass));
     dbService.save(snapshot, typeOfSnapshotClass);
     snapshots.add(snapshot);
     dbService.updateFollowerEvents(followerEvents);
     dbService.updateFollower(follower);
     dbService.updateFollowing(following);
   } else {
     List<Event> differenceEvents =
         snapshotDifference.difference(
             snapshots.get(i), snapshot, followerEvents.getEvents(), eventType);
     differenceEvents.forEach(event -> dbService.save((TypeOfEvent) event, typeOfEventClass));
     followerEvents.getEvents().addAll(differenceEvents);
     dbService.updateFollowerEvents(followerEvents);
   }
 }