1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.jumpmind.symmetric.service.jmx;
21
22 import java.io.ByteArrayOutputStream;
23 import java.math.BigDecimal;
24
25 import org.jumpmind.symmetric.service.IDataExtractorService;
26 import org.jumpmind.symmetric.statistic.IStatisticManager;
27 import org.jumpmind.symmetric.statistic.StatisticName;
28 import org.jumpmind.symmetric.transport.IOutgoingTransport;
29 import org.jumpmind.symmetric.transport.internal.InternalOutgoingTransport;
30 import org.springframework.jmx.export.annotation.ManagedAttribute;
31 import org.springframework.jmx.export.annotation.ManagedOperation;
32 import org.springframework.jmx.export.annotation.ManagedOperationParameter;
33 import org.springframework.jmx.export.annotation.ManagedOperationParameters;
34 import org.springframework.jmx.export.annotation.ManagedResource;
35
36 @ManagedResource(description = "The management interface for outgoing synchronization")
37 public class OutgoingManagementService {
38
39 private IStatisticManager statisticManager;
40
41 private IDataExtractorService dataExtractorService;
42
43 public void setStatisticManager(IStatisticManager statisticManager) {
44 this.statisticManager = statisticManager;
45 }
46
47 @ManagedAttribute(description = "Get the average number of events in each batch since the last statistic flush")
48 public BigDecimal getPeriodicAverageEventsPerBatch() {
49 return this.statisticManager.getStatistic(StatisticName.OUTGOING_EVENTS_PER_BATCH).getAverageValue();
50 }
51
52 @ManagedAttribute(description = "Get the average number of events in each batch for the lifetime of the server")
53 public BigDecimal getServerLifetimeAverageEventsPerBatch() {
54 return this.statisticManager.getStatistic(StatisticName.OUTGOING_EVENTS_PER_BATCH).getLifetimeAverageValue();
55 }
56
57 @ManagedAttribute(description = "Get the average number of milliseconds it takes to batch an event since the last statistic flush")
58 public BigDecimal getPeriodicAverageMsPerEventBatched() {
59 return this.statisticManager.getStatistic(StatisticName.OUTGOING_MS_PER_EVENT_BATCHED).getAverageValue();
60 }
61
62 @ManagedAttribute(description = "Get the average number of milliseconds it takes to batch an event for the lifetime of the server")
63 public BigDecimal getServerLifetimeAverageMsPerEventBatched() {
64 return this.statisticManager.getStatistic(StatisticName.OUTGOING_MS_PER_EVENT_BATCHED)
65 .getLifetimeAverageValue();
66 }
67
68 @ManagedOperation(description = "Show a batch in SymmetricDS Data Format.")
69 @ManagedOperationParameters( { @ManagedOperationParameter(name = "batchId", description = "The batch ID to display") })
70 public String showBatch(String batchId) throws Exception {
71 ByteArrayOutputStream out = new ByteArrayOutputStream();
72 IOutgoingTransport transport = new InternalOutgoingTransport(out);
73 dataExtractorService.extractBatchRange(transport, batchId, batchId);
74 transport.close();
75 out.close();
76 return out.toString();
77 }
78
79 public void setDataExtractorService(IDataExtractorService dataExtractorService) {
80 this.dataExtractorService = dataExtractorService;
81 }
82 }