8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2009 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: LoggingThread.java,v 1.2 2009/07/24 20:02:23 ww203982 Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bcb85423bc6855cb1c7accc69fa051e1771c000aMark de Reeper/*
bcb85423bc6855cb1c7accc69fa051e1771c000aMark de Reeper * Portions Copyrighted 2012 ForgeRock Inc
bcb85423bc6855cb1c7accc69fa051e1771c000aMark de Reeper */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.log.handlers;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.util.ThreadPool;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.util.ThreadPoolException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Lunaimport org.forgerock.util.thread.listener.ShutdownListener;
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Lunaimport org.forgerock.util.thread.listener.ShutdownPriority;
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Lunaimport org.forgerock.util.thread.listener.ShutdownManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class LoggingThread {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static LoggingThread instance = null;
bcb85423bc6855cb1c7accc69fa051e1771c000aMark de Reeper private ThreadPool thread;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected LoggingThread() {
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna // Don't load the Debug object in static block as it can
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna // cause issues when doing a container restart.
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna thread = new ThreadPool("LoggingThread", 1, 0, false, Debug.getInstance("amLogging"));
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna shutdownMan.addShutdownListener(
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna new ShutdownListener() {
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna public void shutdown() {
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna thread.shutdown();
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna instance = null;
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna }
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna }, ShutdownPriority.LOWEST
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna );
57a1b25dcdf865eacb2fe2e17c5ca83e942da047David Luna
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public synchronized static LoggingThread getInstance() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (instance == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster instance = new LoggingThread();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return instance;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void run(Runnable task) throws ThreadPoolException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster thread.run(task);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}