/***************************************************************************
 * Copyright 2011 by
 *  + Christian-Albrechts-University of Kiel
 *    + Department of Computer Science
 *      + Software Engineering Group 
 *  and others.
 *
 * 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 kieker.common.namedRecordPipe;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 
 * @author Andre van Hoorn, Jan Waller
 */
public enum Broker { // Singleton pattern (Effective Java #3)
	INSTANCE;

	// private static final Log LOG = LogFactory.getLog(Broker.class); // NOPMD (Logger on enum)

	/**
	 * Access synchronized through synchronized method {@link #acquirePipe(String)} !
	 */
	private transient final ConcurrentHashMap<String, Pipe> pipeMap = new ConcurrentHashMap<String, Pipe>();

	/**
	 * Returns a connection with name @a pipeName. If a connection with this
	 * name does not exist prior to the call, it is created.
	 */
	public Pipe acquirePipe(final String pipeName) throws IllegalArgumentException {
		Pipe conn;
		synchronized (this) {
			if ((pipeName == null) || (pipeName.length() == 0)) {
				// Broker.LOG.error(errorMsg); no need to log if thrown
				throw new IllegalArgumentException("pipeName must not be null or empty!  (Found: " + pipeName + ")");
			}
			conn = this.pipeMap.putIfAbsent(pipeName, new Pipe(pipeName));
		}
		return conn;
	}
}

@@ -1863,16 +1863,60 @@
 );%0A%09%09%09%7D%0A
+%09%09%09final Pipe newPipe = new Pipe(pipeName);%0A
 %09%09%09conn 
@@ -1959,30 +1959,72 @@
  new
- 
 Pipe
-(pipeName));%0A%09%09%7D%0A
+);%0A%09%09%09if (conn == null) %7B%0A%09%09%09%09return newPipe;%0A%09%09%09%7D else %7B%0A%09%09
 %09%09re
@@ -2034,13 +2034,22 @@
 n conn;%0A
+%09%09%09%7D%0A%09%09%7D%0A
 %09%7D%0A%7D%0A

fix bug in Pipe construction (junit broken)