001    /*
002     * Copyright 2009-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.sdk.unboundidds.logs;
022    
023    
024    
025    import com.unboundid.util.NotExtensible;
026    import com.unboundid.util.ThreadSafety;
027    import com.unboundid.util.ThreadSafetyLevel;
028    
029    
030    
031    /**
032     * <BLOCKQUOTE>
033     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
034     *   LDAP SDK for Java.  It is not available for use in applications that
035     *   include only the Standard Edition of the LDAP SDK, and is not supported for
036     *   use in conjunction with non-UnboundID products.
037     * </BLOCKQUOTE>
038     * This class provides a data structure that holds information about a log
039     * message that may appear in the Directory Server access log.
040     */
041    @NotExtensible()
042    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
043    public abstract class AccessLogMessage
044           extends LogMessage
045    {
046      /**
047       * The serial version UID for this serializable class.
048       */
049      private static final long serialVersionUID = 111497572975341652L;
050    
051    
052    
053      // The connection ID for this access log message.
054      private final Long connectionID;
055    
056      // The Directory Server instance name for this access log message.
057      private final String instanceName;
058    
059      // The server product name for this access log message.
060      private final String productName;
061    
062      // The startup ID for this access log message;
063      private final String startupID;
064    
065    
066    
067      /**
068       * Creates a new access log message from the provided log message.
069       *
070       * @param  m  The log message to be parsed as an access log message.
071       */
072      protected AccessLogMessage(final LogMessage m)
073      {
074        super(m);
075    
076        productName  = getNamedValue("product");
077        instanceName = getNamedValue("instanceName");
078        startupID    = getNamedValue("startupID");
079        connectionID = getNamedValueAsLong("conn");
080      }
081    
082    
083    
084      /**
085       * Parses the provided string as an access log message.
086       *
087       * @param  s  The string to parse as an access log message.
088       *
089       * @return  The parsed access log message.
090       *
091       * @throws  LogException  If an error occurs while trying to parse the log
092       *                        message.
093       */
094      public static AccessLogMessage parse(final String s)
095             throws LogException
096      {
097        return AccessLogReader.parse(s);
098      }
099    
100    
101    
102    
103      /**
104       * Retrieves the server product name for this access log message.
105       *
106       * @return  The server product name for this access log message, or
107       *          {@code null} if it is not included in the log message.
108       */
109      public final String getProductName()
110      {
111        return productName;
112      }
113    
114    
115    
116      /**
117       * Retrieves the Directory Server instance name for this access log message.
118       *
119       * @return  The Directory Server instance name for this access log message, or
120       *          {@code null} if it is not included in the log message.
121       */
122      public final String getInstanceName()
123      {
124        return instanceName;
125      }
126    
127    
128    
129      /**
130       * Retrieves the Directory Server startup ID for this access log message.
131       *
132       * @return  The Directory Server startup ID for this access log message, or
133       *          {@code null} if it is not included in the log message.
134       */
135      public final String getStartupID()
136      {
137        return startupID;
138      }
139    
140    
141    
142      /**
143       * Retrieves the connection ID for the connection with which this access log
144       * message is associated.
145       *
146       * @return  The connection ID for the connection with which this access log
147       *          message is associated, or {@code null} if it is not included in
148       *          the log message.
149       */
150      public final Long getConnectionID()
151      {
152        return connectionID;
153      }
154    
155    
156    
157      /**
158       * Retrieves the message type for this access log message.
159       *
160       * @return  The message type for this access log message.
161       */
162      public abstract AccessLogMessageType getMessageType();
163    }