Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Firebird Open Source J2EE Connector - JDBC Driver
   *
   * Distributable under LGPL license.
   * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * LGPL License for more details.
  *
  * This file was created by members of the firebird development team.
  * All individual contributions remain the Copyright (C) of those
  * individuals.  Contributors to this file are either listed here or
  * can be obtained from a CVS history command.
  *
  * All rights reserved.
  */
 package org.firebirdsql.management;
 
 import java.util.Map;
 import java.io.*;
 
Implements the Trace/Audit API available new in Firebird 2.5

Author(s):
Thomas Steinmaurer
 
 public class FBTraceManager extends FBServiceManager implements TraceManager {
     
     private Map<StringIntegertraceSessions = Collections.synchronizedMap(new HashMap<StringInteger>());
 	
     private class TraceTask implements Runnable {
     	
     	private ServiceRequestBuffer srb;
     	
     	public TraceTask(ServiceRequestBuffer srb) {
     		this. = srb;
     	}
     	
     	public void run() {
     		try {
     			..println("Start trace");
     			..println("Trace stopped");
     		} catch (FBSQLException e) {
     			
     		}
     	}
     }

Create a new instance of FBTraceManager based on the default GDSType.
 
     public FBTraceManager() {
     }

    
Create a new instance of FBTraceManager based on a given GDSType.

Parameters:
gdsType type must be PURE_JAVA, EMBEDDED, or NATIVE
 
     public FBTraceManager(String gdsType) {
     	super(gdsType);
     }

    
Create a new instance of FBTraceManager based on a given GDSType.

Parameters:
gdsType type must be PURE_JAVA, EMBEDDED, or NATIVE
 
     public FBTraceManager(GDSType gdsType) {
     	super(gdsType);
     }
    
    
Creates and returns the "trace" service request buffer for the Service Manager.

Parameters:
action The isc_action_svc_trace_* action to be used
Returns:
the "trace" service request buffer for the Service Manager.
Throws:
java.sql.SQLException
 
 	private ServiceRequestBuffer getTraceSPB(int actionthrows SQLException {
     	ServiceRequestBuffer traceSPB = getGds().createServiceRequestBuffer(action);
         return traceSPB;
     }

Creates and returns the "trace" service request buffer for the Service Manager.

Parameters:
action The isc_action_svc_trace_* action to be used
traceSessionId The trace session ID
Returns:
the "trace" service request buffer for the Service Manager.
Throws:
java.sql.SQLException
	private ServiceRequestBuffer getTraceSPB(int actionint traceSessionIdthrows SQLException {
		ServiceRequestBuffer traceSPB = getTraceSPB(action);
	    traceSPB.addArgument(.traceSessionId);
	    return traceSPB;
	}

Creates and returns the "trace" service request buffer for the Service Manager.

Parameters:
action The isc_action_svc_trace_* action to be used
traceSessionName The trace session name
configuration The trace configuration. For an example, look into fbtrace.conf in the root directory of your Firebird installation
Returns:
the "trace" service request buffer for the Service Manager.
Throws:
java.sql.SQLException
	private ServiceRequestBuffer getTraceSPB(int actionString traceSessionNameString configurationthrows SQLException {
		ServiceRequestBuffer traceSPB = getTraceSPB(action);
	    traceSPB.addArgument(.traceSessionName);
	    traceSPB.addArgument(.configuration);
	    return traceSPB;
	}


    
Starts a trace session with an optioanl trace session name and configuration

Parameters:
traceSessionName The trace session name (optional)
configuration The trace configuration. For an example, look into fbtrace.conf in the root directory of your Firebird installation
Throws:
java.sql.SQLException
	public void startTraceSession(String traceSessionNameString configurationthrows SQLException {
    	
    	if ((configuration == null) || (configuration.equals(""))) {
    		throw new FBSQLException("No configuration provided");
    	}
    	if (traceSessionName == null) {
    		traceSessionName = "";
    	}
    	
    	synchronized (this) {
        	OutputStream currentLogger = getLogger();
        	if (currentLogger instanceof TraceStream) {
        	    currentLogger = ((TraceStreamcurrentLogger).unwrap();
        	}
        	setLogger(new TraceStream(currentLoggertraceSessionName));
        	
        	Thread t = new Thread(new TraceTask(getTraceSPB(.traceSessionNameconfiguration)));
        	t.start();
    	}
    }

    
Stops a trace session with the given trace session ID

Parameters:
traceSessionId The trace session ID
Throws:
java.sql.SQLException
	public void stopTraceSession(int traceSessionIdthrows SQLException {
    }
    
    
Suspends a trace session with the given trace session ID

Parameters:
traceSessionId The trace session ID
Throws:
java.sql.SQLException
    public void suspendTraceSession(int traceSessionIdthrows SQLException {
    }
    
    
Resumes a trace session with the given trace session ID

Parameters:
traceSessionId The trace session ID
Throws:
java.sql.SQLException
    public void resumeTraceSession(int traceSessionIdthrows SQLException {
    }
    
    
    
List all currently registered trace sessions

	public void listTraceSessions() throws SQLException {
	}

Gets the sessionId for the given name.

Returns null if the sessionName does not exist or hasn't been initialized yet.

If multiple sessions are started with the same name, the last one is returned.

Parameters:
sessionName Name of the session
Returns:
Id of the session or null otherwise
	public Integer getSessionId(String sessionName) {
	    return .get(sessionName);
	}

Loads a configuration from the specified fileName

		FileReader fr = new FileReader(fileName);
		StringBuffer sb = new StringBuffer(256);
		try {
			while ((s = br.readLine()) != null) {
				sb.append(s);
			}
finally {
			br.close();
			fr.close();
		}
		return sb.toString();
	}
	private class TraceStream extends FilterOutputStream {
	    private static final String START_TEXT = "Trace session ID ";
	    
	    private final String sessionName;
	    private volatile boolean lookForSessionId = true;
        public TraceStream(OutputStream outString sessionName) {
            super(out);
            this. = sessionName;
        }
	    
        public void write(byte b[], int offint lenthrows IOException {
            if () {
                findSessionId(bofflen);
                 = false;
            }
            
            super.write(bofflen);
        }

        
Tries to find the session ID

Parameters:
b
off
len
        private void findSessionId(byte[] bint offint len) {
            String sessionStart = new String(bofflen);
            int traceStartIdx = sessionStart.indexOf();
            int sessionIdStart = -1;
            int sessionIdEnd = -1;
            if (traceStartIdx >= 0) {
                sessionIdStart = traceStartIdx + .length();
                if (sessionIdStart < sessionStart.length()) {
                    sessionIdEnd = sessionStart.indexOf(' 'sessionIdStart);
                }
            }
            if (sessionIdStart >= 0 && sessionIdEnd > sessionIdStart && sessionIdEnd < sessionStart.length()) {
                try {
                    int sessionId = Integer.parseInt(sessionStart.substring(sessionIdStartsessionIdEnd));
                    .put(, Integer.valueOf(sessionId));
                } catch (NumberFormatException ex) {
                    // ignore
                }
            }
        }
        
        public OutputStream unwrap() {
            return ;
        }
	}
New to GrepCode? Check out our FAQ X