1 /* 2 * The contents of this file are subject to the terms of the Common Development and 3 * Distribution License (the License). You may not use this file except in compliance with the 4 * License. 5 * 6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 7 * specific language governing permission and limitations under the License. 8 * 9 * When distributing Covered Software, include this CDDL Header Notice in each file and include 10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 11 * Header, with the fields enclosed by brackets [] replaced by your own identifying 12 * information: "Portions copyright [year] [name of copyright owner]". 13 * 14 * Copyright 2016 ForgeRock AS. 15 */ 16 package org.forgerock.audit.handlers.jms; 17 18 import com.fasterxml.jackson.annotation.JsonPropertyDescription; 19 20 /** 21 * This class holds the configuration properties that are used by the {#link BatchPublisher} to control the batch queue 22 * and worker threads that process the items in the queue. 23 */ 24 public class BatchPublisherConfiguration { 25 26 @JsonPropertyDescription("audit.handlers.jms.publisher.batch.batchEnabled") 27 private boolean batchEnabled = false; 28 29 @JsonPropertyDescription("audit.handlers.jms.publisher.batch.capacity") 30 private int capacity = 1; 31 32 @JsonPropertyDescription("audit.handlers.jms.publisher.batch.threadCount") 33 private int threadCount = 1; 34 35 @JsonPropertyDescription("audit.handlers.jms.publisher.batch.maxBatchedEvents") 36 private int maxBatchedEvents = 1; 37 38 @JsonPropertyDescription("audit.handlers.jms.publisher.batch.insertTimeoutSec") 39 private long insertTimeoutSec = 60L; 40 41 @JsonPropertyDescription("audit.handlers.jms.publisher.batch.pollTimeoutSec") 42 private long pollTimeoutSec = 10L; 43 44 @JsonPropertyDescription("audit.handlers.jms.publisher.batch.shutdownTimeoutSec") 45 private long shutdownTimeoutSec = 60L; 46 47 /** 48 * Returns the maximum capacity of the publishing queue. Execution will block if the queue size is at capacity. 49 * 50 * @return the maximum capacity of the publishing queue 51 */ 52 public int getCapacity() { 53 return capacity; 54 } 55 56 /** 57 * Sets the maximum capacity of the publishing queue. 58 * 59 * @param capacity the maximum capacity of the publishing queue 60 */ 61 public void setCapacity(int capacity) { 62 this.capacity = capacity; 63 } 64 65 /** 66 * Returns the count of worker threads to have processing the queue. 67 * 68 * @return the count of worker threads to have processing the queue. 69 */ 70 public int getThreadCount() { 71 return threadCount; 72 } 73 74 /** 75 * Sets the count of worker threads to have processing the queue. 76 * 77 * @param threadCount the count of worker threads to have processing the queue. 78 */ 79 public void setThreadCount(int threadCount) { 80 this.threadCount = threadCount; 81 } 82 83 /** 84 * Returns the maximum count of events that will be expected to be delivered in a single publish call. 85 * 86 * @return the maximum count of events that will be expected to be delivered in a single publish call. 87 */ 88 public int getMaxBatchedEvents() { 89 return maxBatchedEvents; 90 } 91 92 /** 93 * Sets the maximum count of events that will be expected to be delivered in a single publish call. 94 * 95 * @param maxBatchedEvents the maximum count of events 96 */ 97 public void setMaxBatchedEvents(int maxBatchedEvents) { 98 this.maxBatchedEvents = maxBatchedEvents; 99 } 100 101 /** 102 * Returns the timeout in seconds the duration that the queue should block while attempting to offer a new item 103 * for the queue. 104 * 105 * @return timeout in seconds 106 */ 107 public long getInsertTimeoutSec() { 108 return insertTimeoutSec; 109 } 110 111 /** 112 * Sets the timeout in seconds the duration that the queue should block while attempting to offer a new item 113 * for the queue. 114 * 115 * @param insertTimeoutSec timeout in seconds 116 */ 117 public void setInsertTimeoutSec(long insertTimeoutSec) { 118 this.insertTimeoutSec = insertTimeoutSec; 119 } 120 121 /** 122 * Returns the timeout in seconds for the worker threads to wait for a new item to be available in the queue 123 * before exiting. 124 * 125 * @return timeout in seconds 126 */ 127 public long getPollTimeoutSec() { 128 return pollTimeoutSec; 129 } 130 131 /** 132 * Sets the timeout in seconds for the worker threads to wait for a new item to be available in the queue before 133 * exiting. 134 * 135 * @param pollTimeoutSec timeout in seconds 136 */ 137 public void setPollTimeoutSec(long pollTimeoutSec) { 138 this.pollTimeoutSec = pollTimeoutSec; 139 } 140 141 /** 142 * Returnds the timeout in seconds for the publisher to wait for all worker threads to terminate at shutdown. 143 * 144 * @return timeout in seconds 145 */ 146 public long getShutdownTimeoutSec() { 147 return shutdownTimeoutSec; 148 } 149 150 /** 151 * Sets the timeout in seconds for the publisher to wait for all worker threads to terminate at shutdown. 152 * 153 * @param shutdownTimeoutSec timeout in seconds 154 */ 155 public void setShutdownTimeoutSec(long shutdownTimeoutSec) { 156 this.shutdownTimeoutSec = shutdownTimeoutSec; 157 } 158 159 /** 160 * Returns true if handling of audit events should be done in batches. 161 * 162 * @return true if handling of audit events should be done in batches. 163 */ 164 public boolean isBatchEnabled() { 165 return batchEnabled; 166 } 167 168 /** 169 * sets if handling of audit events should be done in batches. 170 * 171 * @param batchEnabled true if handling of audit events should be done in batches. 172 */ 173 public void setBatchEnabled(boolean batchEnabled) { 174 this.batchEnabled = batchEnabled; 175 } 176 }