minor refactor to share code

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@389021 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-03-27 04:53:51 +00:00
parent 5bed19f1c5
commit 4ba19cad18
2 changed files with 61 additions and 19 deletions

View File

@ -36,43 +36,30 @@ import java.util.Iterator;
* *
* @version $Revision: $ * @version $Revision: $
*/ */
public class DestinationDotFileInterceptor extends BrokerFilter { public class DestinationDotFileInterceptor extends DotFileInterceptorSupport {
private static final Log log = LogFactory.getLog(DestinationDotFileInterceptor.class);
protected static final String ID_SEPARATOR = "_"; protected static final String ID_SEPARATOR = "_";
private String file;
public DestinationDotFileInterceptor(Broker next, String file) { public DestinationDotFileInterceptor(Broker next, String file) {
super(next); super(next, file);
} }
public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception { public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception {
Destination answer = super.addDestination(context, destination); Destination answer = super.addDestination(context, destination);
generateDestinationGraph(); generateFile();
return answer; return answer;
} }
public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout)
throws Exception { throws Exception {
super.removeDestination(context, destination, timeout); super.removeDestination(context, destination, timeout);
generateDestinationGraph(); generateFile();
} }
protected void generateDestinationGraph() throws Exception {
if (log.isDebugEnabled()) {
log.debug("Creating destination DOT file at: " + file);
}
PrintWriter writer = new PrintWriter(new FileWriter(file));
try {
generateDestinationGraph(writer);
}
finally {
writer.close();
}
}
protected void generateDestinationGraph(PrintWriter writer) throws Exception { protected void generateFile(PrintWriter writer) throws Exception {
ActiveMQDestination[] destinations = getDestinations(); ActiveMQDestination[] destinations = getDestinations();
// lets split into a tree // lets split into a tree

View File

@ -0,0 +1,55 @@
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.broker.view;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerFilter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.FileWriter;
import java.io.PrintWriter;
/**
* Useful base class
*
* @version $Revision: $
*/
public abstract class DotFileInterceptorSupport extends BrokerFilter {
private final Log log = LogFactory.getLog(DotFileInterceptorSupport.class);
private String file;
public DotFileInterceptorSupport(Broker next, String file) {
super(next);
this.file = file;
}
protected void generateFile() throws Exception {
if (log.isDebugEnabled()) {
log.debug("Creating DOT file at: " + file);
}
PrintWriter writer = new PrintWriter(new FileWriter(file));
try {
generateFile(writer);
}
finally {
writer.close();
}
}
protected abstract void generateFile(PrintWriter writer) throws Exception;
}