From 4ba19cad181206271083f44079397a6182177059 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Mon, 27 Mar 2006 04:53:51 +0000 Subject: [PATCH] minor refactor to share code git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@389021 13f79535-47bb-0310-9956-ffa450edef68 --- .../view/DestinationDotFileInterceptor.java | 25 ++------- .../view/DotFileInterceptorSupport.java | 55 +++++++++++++++++++ 2 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 activemq-core/src/main/java/org/apache/activemq/broker/view/DotFileInterceptorSupport.java diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/view/DestinationDotFileInterceptor.java b/activemq-core/src/main/java/org/apache/activemq/broker/view/DestinationDotFileInterceptor.java index 682623af3d..63a08766f8 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/view/DestinationDotFileInterceptor.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/view/DestinationDotFileInterceptor.java @@ -36,43 +36,30 @@ import java.util.Iterator; * * @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 = "_"; - private String file; public DestinationDotFileInterceptor(Broker next, String file) { - super(next); + super(next, file); + } public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception { Destination answer = super.addDestination(context, destination); - generateDestinationGraph(); + generateFile(); return answer; } public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception { 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(); // lets split into a tree diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/view/DotFileInterceptorSupport.java b/activemq-core/src/main/java/org/apache/activemq/broker/view/DotFileInterceptorSupport.java new file mode 100644 index 0000000000..9cf2d6c60b --- /dev/null +++ b/activemq-core/src/main/java/org/apache/activemq/broker/view/DotFileInterceptorSupport.java @@ -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; +}