1 23 package com.sun.appserv.management.helper; 24 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.Set ; 28 import java.util.HashSet ; 29 import java.util.Collections ; 30 31 import java.io.Serializable ; 32 33 34 import javax.management.Attribute ; 35 36 import com.sun.appserv.management.ext.logging.Logging; 37 import static com.sun.appserv.management.ext.logging.Logging.*; 38 import com.sun.appserv.management.ext.logging.LogQuery; 39 import com.sun.appserv.management.ext.logging.LogModuleNames; 40 import com.sun.appserv.management.ext.logging.LogQueryResult; 41 import com.sun.appserv.management.ext.logging.LogQueryEntry; 42 import com.sun.appserv.management.ext.logging.LogQueryResultImpl; 43 44 import com.sun.appserv.management.util.misc.GSetUtil; 45 46 47 48 49 65 public final class StatefulLoggingHelper extends Helper 66 { 67 private Logging mLogging; 68 69 private String mLogFile; 70 private long mStartIndex; 71 private Set <String > mModules; 72 private boolean mSearchForward; 73 private int mMaxRecords; 74 private Long mStartTime; 75 private Long mStopTime; 76 private String mLogLevel; 77 private List <Attribute > mAttrs; 78 79 82 public 83 StatefulLoggingHelper( final Logging logging ) 84 { 85 super( logging.getDomainRoot() ); 86 mLogging = logging; 87 88 mLogFile = MOST_RECENT_NAME; 89 mStartIndex = FIRST_RECORD; 90 mSearchForward = true; 91 mLogLevel = LOWEST_SUPPORTED_QUERY_LEVEL; 92 mModules = LogModuleNames.ALL_NAMES; 93 mMaxRecords = ALL_RECORDS; 94 mStartTime = null; 95 mStopTime = null; 96 mAttrs = new ArrayList <Attribute >(); 97 } 98 99 public Logging 100 getLogging() 101 { 102 return mLogging; 103 } 104 105 public String getLogFile() { return mLogFile; } 106 public long getStartIndex() { return mStartIndex; } 107 public Set <String > getModules() { return mModules; } 108 public List <Attribute > getAttrs() { return mAttrs; } 109 public boolean getSearchForward() { return mSearchForward; } 110 public long getStartTime() { return mStartTime; } 111 public long getStopTime() { return mStopTime; } 112 public String getLogLevel() { return mLogLevel; } 113 public int getMaxRecords() { return mMaxRecords; } 114 115 116 120 public void 121 setLogFile( final String name ) 122 { 123 if ( ! mLogFile.equals( name ) ) 124 { 125 mLogFile = name; 126 setStartIndex( getSearchForward() ? FIRST_RECORD : LAST_RECORD ); 127 } 128 129 } 130 131 public void 132 setStartIndex( final int startIndex ) 133 { 134 mStartIndex = startIndex; 135 } 136 137 public void 138 setLogLevel( final String logLevel ) 139 { 140 mLogLevel = logLevel; 141 } 142 143 public void 144 setMaxRecords( final int maxRecords ) 145 { 146 mMaxRecords = maxRecords; 147 } 148 149 150 public void 151 setModules( final Set <String > modules ) 152 { 153 mModules = modules; 154 } 155 156 public void 157 setModule( final String module ) 158 { 159 mModules = GSetUtil.newSet( module ); 160 } 161 162 public void 163 setAttrs( final List <Attribute > attrs ) 164 { 165 mAttrs.clear(); 166 mAttrs.addAll( attrs ); 167 } 168 169 public void 170 setSearchForward( final boolean searchForward ) 171 { 172 mSearchForward = true; 173 } 174 175 public void 176 setStartTime( final Long startTime ) 177 { 178 mStartTime = startTime; 179 } 180 181 public void 182 setStopTime( final Long stopTime ) 183 { 184 mStopTime = stopTime; 185 } 186 187 193 public LogQueryResult 194 query() 195 { 196 final Logging logging = getLogging(); 197 assert( logging != null ); 198 199 final LogQueryResult result = logging.queryServerLog( 200 mLogFile, 201 mStartIndex, 202 mSearchForward, 203 mMaxRecords, 204 mStartTime, 205 mStopTime, 206 mLogLevel, 207 mModules, 208 mAttrs ); 209 210 final LogQueryEntry[] entries = result.getEntries(); 211 if ( entries.length != 0 ) 212 { 213 if ( mSearchForward ) 215 { 216 mStartIndex = entries[ entries.length - 1 ].getRecordNumber() + 1; 217 } 218 else 219 { 220 mStartIndex = entries[ 0 ].getRecordNumber(); 221 } 222 } 223 224 return result; 225 } 226 } 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | Popular Tags |