View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
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  }