/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: RemoteHandler.java,v 1.18 2009/12/13 22:58:06 hvijay Exp $
*
* Portions Copyrighted 2011-2015 ForgeRock AS.
*/
/**
* The class which publishes the log message to a remote log service. Also
* does buffering of LogRecords upto the number specified in the log
* configuration. This buffer is emptied when the number of log records in the
* buffer reaches the specified number or when the specified time
* interval is exceeded.
*/
static {
}
private int recCountLimit;
// Map with loggedBySID as key & reqSet as value.
// It's to make remote loggging work properly when buffering is enabled
// and log request is directed to different OpenAM servers.
private boolean timeBufferingEnabled = false;
private void configure() {
try {
} catch (NumberFormatException e) {
recCountLimit = 1;
}
} else {
recCountLimit = 1;
}
{
timeBufferingEnabled = true;
}
try {
} catch (MalformedURLException mue) {
if (Debug.warningEnabled()) {
}
}
}
/**
* Constructor in which the configuration of the handler is done.
* @param dummyParam dummy parameter.
* To make instantation generic for all handlers.
*/
configure();
if (timeBufferingEnabled) {
}
//Redundant instantiation of FlushTask for early class loading
//and hence performance improvement.
}
/**
* This method sends the LogRecord to the remote logging service.
* @param logRecord The LogRecord to be published to the remote
* logging service.
*/
if (Debug.warningEnabled()) {
":RemoteHandler.publish : formatted xml is null");
}
return;
}
if (logRecord instanceof ILogRecord) {
if (loggedBySid != null) {
}
}
}
this.recCount++;
if (this.recCount >= recCountLimit) {
if (Debug.messageEnabled()) {
+ recCount + " records, flushing all");
}
}
}
/**
* Flushes any buffered output by calling flush(), and then close
* the handler and free all associated resources with this handler.
*/
public void close() {
flush();
}
/**
* Flush any buffered output.
*/
public synchronized void flush() {
if (recCount <= 0) {
if (Debug.messageEnabled()) {
"in buffer to send");
}
return;
}
if (Debug.messageEnabled()) {
}
try {
if (logHostURL == null) {
this.recCount = 0;
return;
}
+ " on remote machine");
if (thisAMException == null) {
thisAMException = "RemoteHandler.flush(): " +
respContent + " on remote machine";
}
}
}
}
} catch (Exception e) {
}
this.recCount = 0;
if (thisAMException != null) {
throw new AMLogException(thisAMException);
}
}
/**
* Copy the existing request set map and pass it on to ThreadPool as part
* of a FlushTask. Initiatize a new map as the new request set map for
* future remote logging calls.
*/
public synchronized void nonBlockingFlush() {
if (recCount <= 0) {
if (Debug.messageEnabled()) {
"in buffer to send");
}
return;
}
try {
// Get an instance as required otherwise it can cause issues on container restart.
} catch (ThreadPoolException ex) {
//Use current thread to complete the task if ThreadPool can not
//execute it.
if (Debug.messageEnabled()) {
". Performing blocking flush.");
}
}
this.recCount = 0;
}
//
// if remote logging service and protocol, host, and port
// are null, get them from the logging service url in the
// AMConfig.properties file.
//
{
if (Debug.messageEnabled()) {
}
return (logServURL);
}
if (Debug.messageEnabled()) {
" sessionProtocol: " + sessionProtocol +
" sessionHost: " + sessionHost +
" sessionPort: " + sessionPort +
" sessionURI: " + sessionURI);
}
try {
if (Debug.messageEnabled()) {
"RemoteHandler.getLogHostURL(): WebtopNaming logging"
+ "service URL: " + loggingURL);
}
} catch (URLNotFoundException unfe) {
"RemoteHandler.getLogHostURL(): URLNotFoundException: ", unfe);
return null;
}
return loggingURL;
}
/**
* This inner class is instantiated by the nonBlockingFlush() method to
* create task for flushing out (asynchronously) the current buffer of
* log record requests.
*/
this.logReqsMap = reqSetMap;
}
public void run() {
if (Debug.messageEnabled()) {
"sending buffered records");
}
try {
if (logHostURL == null) {
"logHostURL is null");
return;
}
respContent + " on remote machine");
if (thisAMException == null) {
"RemoteHandler.FlushTask.run(): " +
respContent + " on remote machine";
}
}
}
}
} catch (Exception e) {
}
if(thisAMException != null){
throw new AMLogException(thisAMException);
}
}
}
private long runPeriod;
}
/**
* The method which implements the GeneralTaskRunnable.
*/
public void run() {
if (Debug.messageEnabled()) {
}
flush();
}
/**
* Methods that need to be implemented from GeneralTaskRunnable.
*/
public boolean isEmpty() {
return true;
}
return false;
}
return false;
}
public long getRunPeriod() {
return runPeriod;
}
}
private void startTimeBufferingThread() {
long interval;
} else {
}
interval *= 1000;
if(bufferTask == null){
try {
} catch (IllegalArgumentException e) {
e.getMessage());
} catch (IllegalStateException e) {
if (Debug.messageEnabled()) {
+ e.getMessage());
}
}
if (Debug.messageEnabled()) {
}
}
}
private void stopBufferTimer() {
if(bufferTask != null) {
bufferTask.cancel();
bufferTask = null;
if (Debug.messageEnabled()) {
}
}
}
}