/** * Fills recordedEvents with the events in RecordedEventStore. */ private void fillRecordedEvents() { Collection<RecordedEvent> events = recordedEventStore.getEvents(); for (RecordedEvent event : events) { this.recordedEvents.offer(event); } }
/** * Empty the RecordedEventStore and sets the RecordAndReplayStatus. */ private void finishReplay() { recordedEventStore.popEvents(); recordAndReplayCurrentStatus.setStatus(RecordAndReplayStatus.REPLAY_FINISHED); // stops the replay if every recorded event was already replayed }
/** * Deserialize RecordedEvents. * @param recordingPath path where the data was saved. */ void deserializeRecordedEvents(String recordingPath) { String filepath = recordingPath + EVENT_DIR + recordAndReplayUtils.getFileCount() + JSON; recordAndReplayUtils.setFileCount(recordAndReplayUtils.getFileCount() + 1); recordedEventStore.setEvents(recordedEventSerializer.deserializeRecordedEvents(filepath)); logger.info("RecordedEvents Deserialization completed!"); }
extraDataManager = context.get(ExtraBlockDataManager.class); RecordedEventStore recordedEventStore = new RecordedEventStore(); recordAndReplayUtils = new RecordAndReplayUtils(); CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE); recordAndReplayCurrentStatus = new RecordAndReplayCurrentStatus(); RecordedEventStore eventStore = new RecordedEventStore(); RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils(); CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap(); entity = entityManager.create(); Long id = entity.getId(); eventStore.add(new RecordedEvent(id, new AttackButton(), 1, 1)); eventStore.add(new RecordedEvent(id, new AttackButton(), 2, 2)); eventStore.add(new RecordedEvent(id, new AttackButton(), 3, 3));
/** * Receives a PendingEvent and add it as a RecordedEvent in the RecordedEventStore if it is an event type that should be * recorded. * @param pendingEvent PendingEvent to be checked and added * @return If the event was added to the RecordedEventStore */ public boolean addEvent(PendingEvent pendingEvent) { if (shouldRecordEvent(pendingEvent)) { long timestamp = System.currentTimeMillis() - this.startTime; Event e = this.eventCopier.copyEvent(pendingEvent.getEvent()); PendingEvent newPendingEvent = new PendingEvent(pendingEvent.getEntity(), e); RecordedEvent recordedEvent; if (pendingEvent.getComponent() == null) { recordedEvent = new RecordedEvent(newPendingEvent.getEntity().getId(), newPendingEvent.getEvent(), timestamp, this.eventCounter); } else { recordedEvent = new RecordedEvent(newPendingEvent.getEntity().getId(), newPendingEvent.getEvent(), newPendingEvent.getComponent(), timestamp, eventCounter); } this.eventCounter++; return recordedEventStore.add(recordedEvent); } else { return false; } }
BiomeManager biomeManager = context.get(BiomeManager.class); ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class); RecordedEventStore recordedEventStore = new RecordedEventStore(); RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils(); context.put(RecordAndReplayUtils.class, recordAndReplayUtils);
CharacterStateEventPositionMap characterStateEventPositionMap = context.get(CharacterStateEventPositionMap.class); DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = context.get(DirectionAndOriginPosRecorderList.class); RecordedEventStore recordedEventStore = new RecordedEventStore(); RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, environment); context.put(RecordAndReplaySerializer.class, recordAndReplaySerializer);
/** * Serialize RecordedEvents. * @param recordingPath path where the data should be saved. */ public void serializeRecordedEvents(String recordingPath) { String filepath = recordingPath + EVENT_DIR + recordAndReplayUtils.getFileCount() + JSON; recordAndReplayUtils.setFileAmount(recordAndReplayUtils.getFileAmount() + 1); recordAndReplayUtils.setFileCount(recordAndReplayUtils.getFileCount() + 1); recordedEventSerializer.serializeRecordedEvents(recordedEventStore.popEvents(), filepath); logger.info("RecordedEvents Serialization completed!"); }