diff options
Diffstat (limited to 'qpid/java/broker/src/main')
435 files changed, 0 insertions, 59821 deletions
diff --git a/qpid/java/broker/src/main/java/broker.bnd b/qpid/java/broker/src/main/java/broker.bnd deleted file mode 100755 index 8296764126..0000000000 --- a/qpid/java/broker/src/main/java/broker.bnd +++ /dev/null @@ -1,26 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# - -ver: 0.25.0 - -Bundle-SymbolicName: qpid-broker -Bundle-Version: ${ver} -Export-Package: *;version=${ver} -Bundle-RequiredExecutionEnvironment: J2SE-1.5 - diff --git a/qpid/java/broker/src/main/java/fallback-log4j.properties b/qpid/java/broker/src/main/java/fallback-log4j.properties deleted file mode 100644 index 7b95a89924..0000000000 --- a/qpid/java/broker/src/main/java/fallback-log4j.properties +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -log4j.rootCategory=${amqj.logging.level}, console - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.Threshold=all -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%t %d %p [%c{4}] %m%n diff --git a/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java b/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java deleted file mode 100644 index 54ca574871..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java +++ /dev/null @@ -1,1206 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.log4j; - -import org.apache.log4j.helpers.CountingQuietWriter; -import org.apache.log4j.helpers.LogLog; -import org.apache.log4j.helpers.OptionConverter; -import org.apache.log4j.spi.LoggingEvent; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.Writer; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.zip.GZIPOutputStream; - -/** - * <p>CompositeRollingAppender combines RollingFileAppender and DailyRollingFileAppender<br> It can function as either - * or do both at the same time (making size based rolling files like RollingFileAppender until a data/time boundary is - * crossed at which time it rolls all of those files as per the DailyRollingFileAppender) based on the setting for - * <code>rollingStyle</code>.<br> <br> To use CompositeRollingAppender to roll log files as they reach a certain size - * (like RollingFileAppender), set rollingStyle=1 (@see config.size)<br> To use CompositeRollingAppender to roll log - * files at certain time intervals (daily for example), set rollingStyle=2 and a datePattern (@see config.time)<br> To - * have CompositeRollingAppender roll log files at a certain size AND rename those according to time intervals, set - * rollingStyle=3 (@see config.composite)<br> - * - * <p>A of few additional optional features have been added:<br> -- Attach date pattern for current log file (@see - * staticLogFileName)<br> -- Backup number increments for newer files (@see countDirection)<br> -- Infinite number of - * backups by file size (@see maxSizeRollBackups)<br> <br> <p>A few notes and warnings: For large or infinite number of - * backups countDirection > 0 is highly recommended, with staticLogFileName = false if time based rolling is also used - * -- this will reduce the number of file renamings to few or none. Changing staticLogFileName or countDirection - * without clearing the directory could have nasty side effects. If Date/Time based rolling is enabled, - * CompositeRollingAppender will attempt to roll existing files in the directory without a date/time tag based on the - * last modified date of the base log files last modification.<br> <br> <p>A maximum number of backups based on - * date/time boundries would be nice but is not yet implemented.<br> - * - * @author Kevin Steppe - * @author Heinz Richter - * @author Eirik Lygre - * @author Ceki Gülcü - * @author Martin Ritchie - */ -public class QpidCompositeRollingAppender extends FileAppender -{ - // The code assumes that the following 'time' constants are in a increasing - // sequence. - static final int TOP_OF_TROUBLE = -1; - static final int TOP_OF_MINUTE = 0; - static final int TOP_OF_HOUR = 1; - static final int HALF_DAY = 2; - static final int TOP_OF_DAY = 3; - static final int TOP_OF_WEEK = 4; - static final int TOP_OF_MONTH = 5; - - /** Style of rolling to use */ - static final int BY_SIZE = 1; - static final int BY_DATE = 2; - static final int BY_COMPOSITE = 3; - - // Not currently used - static final String S_BY_SIZE = "Size"; - static final String S_BY_DATE = "Date"; - static final String S_BY_COMPOSITE = "Composite"; - - /** The date pattern. By default, the pattern is set to "'.'yyyy-MM-dd" meaning daily rollover. */ - private String datePattern = "'.'yyyy-MM-dd"; - - /** - * The actual formatted filename that is currently being written to or will be the file transferred to on roll over - * (based on staticLogFileName). - */ - private String scheduledFilename = null; - - /** The timestamp when we shall next recompute the filename. */ - private long nextCheck = System.currentTimeMillis() - 1; - - /** Holds date of last roll over */ - private Date now = new Date(); - - private SimpleDateFormat sdf; - - /** Helper class to determine next rollover time */ - private RollingCalendar rc = new RollingCalendar(); - - private long maxFileSize = 10 * 1024 * 1024; - - private int maxSizeRollBackups = 0; - private int curSizeRollBackups = 0; - - private int maxTimeRollBackups = -1; - private int curTimeRollBackups = 0; - - private int countDirection = -1; - - private int rollingStyle = BY_COMPOSITE; - private boolean rollDate = true; - private boolean rollSize = true; - - private boolean staticLogFileName = true; - - private String baseFileName; - - private boolean compress = false; - - private boolean compressAsync = false; - - private boolean zeroBased = false; - - private String backupFilesToPath = null; - private final ConcurrentLinkedQueue<CompressJob> _compress = new ConcurrentLinkedQueue<CompressJob>(); - private AtomicBoolean _compressing = new AtomicBoolean(false); - private static final String COMPRESS_EXTENSION = ".gz"; - - /** The default constructor does nothing. */ - public QpidCompositeRollingAppender() - { } - - /** - * Instantiate a <code>CompositeRollingAppender</code> and open the file designated by <code>filename</code>. The - * opened filename will become the ouput destination for this appender. - */ - public QpidCompositeRollingAppender(Layout layout, String filename, String datePattern) throws IOException - { - this(layout, filename, datePattern, true); - } - - /** - * Instantiate a CompositeRollingAppender and open the file designated by <code>filename</code>. The opened filename - * will become the ouput destination for this appender. - * - * <p>If the <code>append</code> parameter is true, the file will be appended to. Otherwise, the file desginated by - * <code>filename</code> will be truncated before being opened. - */ - public QpidCompositeRollingAppender(Layout layout, String filename, boolean append) throws IOException - { - super(layout, filename, append); - } - - /** - * Instantiate a CompositeRollingAppender and open the file designated by <code>filename</code>. The opened filename - * will become the ouput destination for this appender. - */ - public QpidCompositeRollingAppender(Layout layout, String filename, String datePattern, boolean append) - throws IOException - { - super(layout, filename, append); - this.datePattern = datePattern; - activateOptions(); - } - - /** - * Instantiate a CompositeRollingAppender and open the file designated by <code>filename</code>. The opened filename - * will become the output destination for this appender. - * - * <p>The file will be appended to. DatePattern is default. - */ - public QpidCompositeRollingAppender(Layout layout, String filename) throws IOException - { - super(layout, filename); - } - - /** - * The <b>DatePattern</b> takes a string in the same format as expected by {@link java.text.SimpleDateFormat}. This - * options determines the rollover schedule. - */ - public void setDatePattern(String pattern) - { - datePattern = pattern; - } - - /** Returns the value of the <b>DatePattern</b> option. */ - public String getDatePattern() - { - return datePattern; - } - - /** There is zero backup files by default. */ /** Returns the value of the <b>maxSizeRollBackups</b> option. */ - public int getMaxSizeRollBackups() - { - return maxSizeRollBackups; - } - - /** - * Get the maximum size that the output file is allowed to reach before being rolled over to backup files. - * - * @since 1.1 - */ - public long getMaximumFileSize() - { - return maxFileSize; - } - - /** - * <p>Set the maximum number of backup files to keep around based on file size. - * - * <p>The <b>MaxSizeRollBackups</b> option determines how many backup files are kept before the oldest is erased. - * This option takes an integer value. If set to zero, then there will be no backup files and the log file will be - * truncated when it reaches <code>MaxFileSize</code>. If a negative number is supplied then no deletions will be - * made. Note that this could result in very slow performance as a large number of files are rolled over unless - * {@link #setCountDirection} up is used. - * - * <p>The maximum applys to -each- time based group of files and -not- the total. Using a daily roll the maximum - * total files would be (#days run) * (maxSizeRollBackups) - */ - public void setMaxSizeRollBackups(int maxBackups) - { - maxSizeRollBackups = maxBackups; - } - - /** - * Set the maximum size that the output file is allowed to reach before being rolled over to backup files. - * - * <p>This method is equivalent to {@link #setMaxFileSize} except that it is required for differentiating the setter - * taking a <code>long</code> argument from the setter taking a <code>String</code> argument by the JavaBeans {@link - * java.beans.Introspector Introspector}. - * - * @see #setMaxFileSize(String) - */ - public void setMaxFileSize(long maxFileSize) - { - this.maxFileSize = maxFileSize; - } - - /** - * Set the maximum size that the output file is allowed to reach before being rolled over to backup files. - * - * <p>This method is equivalent to {@link #setMaxFileSize} except that it is required for differentiating the setter - * taking a <code>long</code> argument from the setter taking a <code>String</code> argument by the JavaBeans {@link - * java.beans.Introspector Introspector}. - * - * @see #setMaxFileSize(String) - */ - public void setMaximumFileSize(long maxFileSize) - { - this.maxFileSize = maxFileSize; - } - - /** - * Set the maximum size that the output file is allowed to reach before being rolled over to backup files. - * - * <p>In configuration files, the <b>MaxFileSize</b> option takes an long integer in the range 0 - 2^63. You can - * specify the value with the suffixes "KB", "MB" or "GB" so that the integer is interpreted being expressed - * respectively in kilobytes, megabytes or gigabytes. For example, the value "10KB" will be interpreted as 10240. - */ - public void setMaxFileSize(String value) - { - maxFileSize = OptionConverter.toFileSize(value, maxFileSize + 1); - } - - protected void setQWForFiles(Writer writer) - { - qw = new CountingQuietWriter(writer, errorHandler); - } - - // Taken verbatum from DailyRollingFileAppender - int computeCheckPeriod() - { - RollingCalendar c = new RollingCalendar(); - // set sate to 1970-01-01 00:00:00 GMT - Date epoch = new Date(0); - if (datePattern != null) - { - for (int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) - { - String r0 = sdf.format(epoch); - c.setType(i); - Date next = new Date(c.getNextCheckMillis(epoch)); - String r1 = sdf.format(next); - if ((r0 != null) && (r1 != null) && !r0.equals(r1)) - { - return i; - } - } - } - - return TOP_OF_TROUBLE; // Deliberately head for trouble... - } - - // Now for the new stuff - /** - * Handles append time behavior for CompositeRollingAppender. This checks if a roll over either by date (checked - * first) or time (checked second) is need and then appends to the file last. - */ - protected void subAppend(LoggingEvent event) - { - - if (rollDate) - { - long n = System.currentTimeMillis(); - if (n >= nextCheck) - { - now.setTime(n); - nextCheck = rc.getNextCheckMillis(now); - - rollOverTime(); - } - } - - if (rollSize) - { - if ((fileName != null) && (((CountingQuietWriter) qw).getCount() >= maxFileSize)) - { - rollOverSize(); - } - } - - super.subAppend(event); - } - - public void setFile(String file) - { - baseFileName = file.trim(); - fileName = file.trim(); - } - - /** - * Creates and opens the file for logging. If <code>staticLogFileName</code> is false then the fully qualified name - * is determined and used. - */ - public synchronized void setFile(String fileName, boolean append) throws IOException - { - if (!staticLogFileName) - { - scheduledFilename = fileName = fileName.trim() + sdf.format(now); - } - - super.setFile(fileName, append, bufferedIO, bufferSize); - - if (append) - { - File f = new File(fileName); - ((CountingQuietWriter) qw).setCount(f.length()); - } - } - - /** - * By default newer files have lower numbers. (countDirection < 0) ie. log.1 is most recent, log.5 is the 5th - * backup, etc... countDirection > 0 does the opposite ie. log.1 is the first backup made, log.5 is the 5th backup - * made, etc. For infinite backups use countDirection > 0 to reduce rollOver costs. - */ - public int getCountDirection() - { - return countDirection; - } - - public void setCountDirection(int direction) - { - countDirection = direction; - } - - /** Style of rolling to Use. BY_SIZE (1), BY_DATE(2), BY COMPOSITE(3) */ - public int getRollingStyle() - { - return rollingStyle; - } - - public void setRollingStyle(int style) - { - rollingStyle = style; - switch (rollingStyle) - { - - case BY_SIZE: - rollDate = false; - rollSize = true; - break; - - case BY_DATE: - rollDate = true; - rollSize = false; - break; - - case BY_COMPOSITE: - rollDate = true; - rollSize = true; - break; - - default: - errorHandler.error("Invalid rolling Style, use 1 (by size only), 2 (by date only) or 3 (both)"); - } - } - - public boolean getStaticLogFileName() - { - return staticLogFileName; - } - - public void setStaticLogFileName(boolean s) - { - staticLogFileName = s; - } - - public void setStaticLogFileName(String value) - { - setStaticLogFileName(OptionConverter.toBoolean(value, true)); - } - - public boolean getCompressBackupFiles() - { - return compress; - } - - public void setCompressBackupFiles(boolean c) - { - compress = c; - } - - public boolean getCompressAsync() - { - return compressAsync; - } - - public void setCompressAsync(boolean c) - { - compressAsync = c; - if (compressAsync) - { - executor = Executors.newFixedThreadPool(1); - - compressor = new Compressor(); - } - } - - public boolean getZeroBased() - { - return zeroBased; - } - - public void setZeroBased(boolean z) - { - zeroBased = z; - } - - /** Path provided in configuration. Used for moving backup files to */ - public String getBackupFilesToPath() - { - return backupFilesToPath; - } - - public void setbackupFilesToPath(String path) - { - File td = new File(path); - if (!td.exists()) - { - td.mkdirs(); - } - - backupFilesToPath = path; - } - - /** - * Initializes based on exisiting conditions at time of <code> activateOptions</code>. The following is done:<br> - * <br> A) determine curSizeRollBackups<br> B) determine curTimeRollBackups (not implemented)<br> C) initiates a - * roll over if needed for crossing a date boundary since the last run. - */ - protected void existingInit() - { - curTimeRollBackups = 0; - - // part A starts here - // This is now down at first log when curSizeRollBackup==0 see rollFile - // part A ends here - - // part B not yet implemented - - // part C - if (staticLogFileName && rollDate) - { - File old = new File(baseFileName); - if (old.exists()) - { - Date last = new Date(old.lastModified()); - if (!(sdf.format(last).equals(sdf.format(now)))) - { - scheduledFilename = baseFileName + sdf.format(last); - LogLog.debug("Initial roll over to: " + scheduledFilename); - rollOverTime(); - } - } - } - - LogLog.debug("curSizeRollBackups after rollOver at: " + curSizeRollBackups); - // part C ends here - - } - - /** - * Sets initial conditions including date/time roll over information, first check, scheduledFilename, and calls - * <code>existingInit</code> to initialize the current # of backups. - */ - public void activateOptions() - { - - // REMOVE removed rollDate from boolean to enable Alex's change - if (datePattern != null) - { - now.setTime(System.currentTimeMillis()); - sdf = new SimpleDateFormat(datePattern); - int type = computeCheckPeriod(); - rc.setType(type); - // next line added as this removes the name check in rollOver - nextCheck = rc.getNextCheckMillis(now); - } - else - { - if (rollDate) - { - LogLog.error("Either DatePattern or rollingStyle options are not set for [" + name + "]."); - } - } - - existingInit(); - - if (rollDate && (fileName != null) && (scheduledFilename == null)) - { - scheduledFilename = fileName + sdf.format(now); - } - - try - { - this.setFile(fileName, true); - } - catch (IOException e) - { - errorHandler.error("Cannot set file name:" + fileName); - } - - super.activateOptions(); - } - - /** - * Rollover the file(s) to date/time tagged file(s). Opens the new file (through setFile) and resets - * curSizeRollBackups. - */ - protected void rollOverTime() - { - - curTimeRollBackups++; - - this.closeFile(); // keep windows happy. - - - rollFile(); - - try - { - curSizeRollBackups = 0; // We're cleared out the old date and are ready for the new - - // new scheduled name - scheduledFilename = fileName + sdf.format(now); - this.setFile(baseFileName, false); - } - catch (IOException e) - { - errorHandler.error("setFile(" + fileName + ", false) call failed."); - } - - } - - /** - * Renames file <code>from</code> to file <code>to</code>. It also checks for existence of target file and deletes - * if it does. - */ - protected void rollFile(String from, String to, boolean compress) - { - if (from.equals(to)) - { - if (compress) - { - LogLog.error("Attempting to compress file with same output name."); - } - - return; - } - - if (backupFilesToPath != null) - { - to = backupFilesToPath + System.getProperty("file.separator") + new File(to).getName(); - } - - File target = new File(to); - - File file = new File(from); - // Perform Roll by renaming - if (!file.getPath().equals(target.getPath())) - { - file.renameTo(target); - } - - // Compress file after it has been moved out the way... this is safe - // as it will gain a .gz ending and we can then safely delete this file - // as it will not be the statically named value. - if (compress) - { - compress(target); - } - - LogLog.debug(from + " -> " + to); - } - - private void compress(File target) - { - if (compressAsync) - { - synchronized (_compress) - { - _compress.offer(new CompressJob(target, target)); - } - - startCompression(); - } - else - { - doCompress(target, target); - } - } - - private void startCompression() - { - if (_compressing.compareAndSet(false, true)) - { - executor.execute(compressor); - } - } - - /** - * Delete the given file that is prepended with the relative path to the log - * directory. - * - * Compress is enabled check for file with COMPRESS_EXTENSION(.gz) - * - * if backupFilesToPath is set then check in this directory not the - * main log directory. - */ - protected void deleteFile(String relativeFileName) - { - String fileName=""; - // If we have configured a backup location then we should look in there - // for the file we are trying to delete - if (backupFilesToPath != null) - { - File file = new File(relativeFileName); - - fileName = backupFilesToPath + System.getProperty("file.separator") + file.getName(); - } - - // If we are compressing the at the extension - if (compress) - { - fileName += COMPRESS_EXTENSION; - } - - - File file = new File(fileName); - - if (file.exists()) - { - file.delete(); - } - } - - /** - * Implements roll overs base on file size. - * - * <p>If the maximum number of size based backups is reached (<code>curSizeRollBackups == maxSizeRollBackups</code) - * then the oldest file is deleted -- it's index determined by the sign of countDirection.<br> If - * <code>countDirection</code> < 0, then files {<code>File.1</code>, ..., <code>File.curSizeRollBackups -1</code>} - * are renamed to {<code>File.2</code>, ..., <code>File.curSizeRollBackups</code>}. Moreover, <code>File</code> is - * renamed <code>File.1</code> and closed.<br> - * - * A new file is created to receive further log output. - * - * <p>If <code>maxSizeRollBackups</code> is equal to zero, then the <code>File</code> is truncated with no backup - * files created. - * - * <p>If <code>maxSizeRollBackups</code> < 0, then <code>File</code> is renamed if needed and no files are deleted. - */ - - // synchronization not necessary since doAppend is alreasy synched - protected void rollOverSize() - { - File file; - - this.closeFile(); // keep windows happy. - - LogLog.debug("rolling over count=" + ((CountingQuietWriter) qw).getCount()); - LogLog.debug("maxSizeRollBackups = " + maxSizeRollBackups); - LogLog.debug("curSizeRollBackups = " + curSizeRollBackups); - LogLog.debug("countDirection = " + countDirection); - - // If maxBackups <= 0, then there is no file renaming to be done. - if (maxSizeRollBackups != 0) - { - rollFile(); - } - - try - { - // This will also close the file. This is OK since multiple - // close operations are safe. - this.setFile(baseFileName, false); - } - catch (IOException e) - { - LogLog.error("setFile(" + fileName + ", false) call failed.", e); - } - } - - /** - * Perform file Rollover ensuring the countDirection is applied along with - * the other options - */ - private void rollFile() - { - LogLog.debug("CD="+countDirection+",start"); - if (countDirection < 0) - { - // If we haven't rolled yet then validate we have the right value - // for curSizeRollBackups - if (curSizeRollBackups == 0) - { - //Validate curSizeRollBackups - curSizeRollBackups = countFileIndex(fileName); - // decrement to offset the later increment - curSizeRollBackups--; - } - - // If we are not keeping an infinite set of backups the delete oldest - if (maxSizeRollBackups > 0) - { - LogLog.debug("CD=-1,curSizeRollBackups:"+curSizeRollBackups); - LogLog.debug("CD=-1,maxSizeRollBackups:"+maxSizeRollBackups); - - // Delete the oldest file. - // curSizeRollBackups is never -1 so infinite backups are ok here - if ((curSizeRollBackups - maxSizeRollBackups) >= 0) - { - //The oldest file is the one with the largest number - // as the 0 is always fileName - // which moves to fileName.1 etc. - LogLog.debug("CD=-1,deleteFile:"+curSizeRollBackups); - deleteFile(fileName + '.' + curSizeRollBackups); - // decrement to offset the later increment - curSizeRollBackups--; - } - } - /* - map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}. - */ - for (int i = curSizeRollBackups; i >= 1; i--) - { - String oldName = (fileName + "." + i); - String newName = (fileName + '.' + (i + 1)); - - // Ensure that when compressing we rename the compressed archives - if (compress) - { - rollFile(oldName + COMPRESS_EXTENSION, newName + COMPRESS_EXTENSION, false); - } - else - { - rollFile(oldName, newName, false); - } - } - - curSizeRollBackups++; - // Rename fileName to fileName.1 - rollFile(fileName, fileName + ".1", compress); - - } // REMOVE This code branching for Alexander Cerna's request - else if (countDirection == 0) - { - // rollFile based on date pattern - now.setTime(System.currentTimeMillis()); - String newFile = fileName + sdf.format(now); - - // If we haven't rolled yet then validate we have the right value - // for curSizeRollBackups - if (curSizeRollBackups == 0) - { - //Validate curSizeRollBackups - curSizeRollBackups = countFileIndex(newFile); - // to balance the increment just coming up. as the count returns - // the next free number not the last used. - curSizeRollBackups--; - } - - // If we are not keeping an infinite set of backups the delete oldest - if (maxSizeRollBackups > 0) - { - // Don't prune older files if they exist just go for the last - // one based on our maxSizeRollBackups. This means we may have - // more files left on disk that maxSizeRollBackups if this value - // is adjusted between runs but that is an acceptable state. - // Otherwise we would have to check on startup that we didn't - // have more than maxSizeRollBackups and prune then. - - if (((curSizeRollBackups - maxSizeRollBackups) >= 0)) - { - LogLog.debug("CD=0,curSizeRollBackups:"+curSizeRollBackups); - LogLog.debug("CD=0,maxSizeRollBackups:"+maxSizeRollBackups); - - // delete the first and keep counting up. - int oldestFileIndex = curSizeRollBackups - maxSizeRollBackups + 1; - LogLog.debug("CD=0,deleteFile:"+oldestFileIndex); - deleteFile(newFile + '.' + oldestFileIndex); - } - } - - - String finalName = newFile; - - curSizeRollBackups++; - - // Add rollSize if it is > 0 - if (curSizeRollBackups > 0 ) - { - finalName = newFile + '.' + curSizeRollBackups; - - } - - rollFile(fileName, finalName, compress); - } - else - { // countDirection > 0 - // If we haven't rolled yet then validate we have the right value - // for curSizeRollBackups - if (curSizeRollBackups == 0) - { - //Validate curSizeRollBackups - curSizeRollBackups = countFileIndex(fileName); - // to balance the increment just coming up. as the count returns - // the next free number not the last used. - curSizeRollBackups--; - } - - // If we are not keeping an infinite set of backups the delete oldest - if (maxSizeRollBackups > 0) - { - LogLog.debug("CD=1,curSizeRollBackups:"+curSizeRollBackups); - LogLog.debug("CD=1,maxSizeRollBackups:"+maxSizeRollBackups); - - // Don't prune older files if they exist just go for the last - // one based on our maxSizeRollBackups. This means we may have - // more files left on disk that maxSizeRollBackups if this value - // is adjusted between runs but that is an acceptable state. - // Otherwise we would have to check on startup that we didn't - // have more than maxSizeRollBackups and prune then. - - if (((curSizeRollBackups - maxSizeRollBackups) >= 0)) - { - // delete the first and keep counting up. - int oldestFileIndex = curSizeRollBackups - maxSizeRollBackups + 1; - LogLog.debug("CD=1,deleteFile:"+oldestFileIndex); - deleteFile(fileName + '.' + oldestFileIndex); - } - } - - - curSizeRollBackups++; - - rollFile(fileName, fileName + '.' + curSizeRollBackups, compress); - - } - LogLog.debug("CD="+countDirection+",done"); - } - - - private int countFileIndex(String fileName) - { - return countFileIndex(fileName, true); - } - /** - * Use filename as a base name and find what count number we are up to by - * looking at the files in this format: - * - * <filename>.<count>[COMPRESS_EXTENSION] - * - * If a count value of 1 cannot be found then a directory listing is - * performed to try and identify if there is a valid value for <count>. - * - * - * @param fileName the basefilename to use - * @param checkBackupLocation should backupFilesToPath location be checked for existing backups - * @return int the next free index - */ - private int countFileIndex(String fileName, boolean checkBackupLocation) - { - String testFileName; - - // It is possible for index 1..n to be missing leaving n+1..n+1+m logs - // in this scenario we should still return n+1+m+1 - int index=1; - - testFileName = fileName + "." + index; - - // Bail out early if there is a problem with the file - if (new File(testFileName) == null - || new File(testFileName + COMPRESS_EXTENSION) == null) - - { - return index; - } - - // Check that we do not have the 1..n missing scenario - if (!(new File(testFileName).exists() - || new File(testFileName + COMPRESS_EXTENSION).exists())) - - { - int max=0; - String prunedFileName = new File(fileName).getName(); - - // Look through all files to find next index - if (new File(fileName).getParentFile() != null) - { - for (File file : new File(fileName).getParentFile().listFiles()) - { - String name = file.getName(); - - if (name.startsWith(prunedFileName) && !name.equals(prunedFileName)) - { - String parsedCount = name.substring(prunedFileName.length() + 1); - - if (parsedCount.endsWith(COMPRESS_EXTENSION)) - { - parsedCount = parsedCount.substring(0, parsedCount.indexOf(COMPRESS_EXTENSION)); - } - - try - { - max = Integer.parseInt(parsedCount); - - // if we got a good value then update our index value. - if (max > index) - { - // +1 as we want to return the next free value. - index = max + 1; - } - } - catch (NumberFormatException nfe) - { - //ignore it assume file doesn't exist. - } - } - } - } - - // Update testFileName - testFileName = fileName + "." + index; - } - - - while (new File(testFileName).exists() - || new File(testFileName + COMPRESS_EXTENSION).exists()) - { - index++; - testFileName = fileName + "." + index; - } - - if (checkBackupLocation && index == 1 && backupFilesToPath != null) - { - LogLog.debug("Trying backup location:"+backupFilesToPath + System.getProperty("file.separator") + fileName); - return countFileIndex(backupFilesToPath + System.getProperty("file.separator") + new File(fileName).getName(), false); - } - - return index; - } - - protected synchronized void doCompress(File from, File to) - { - String toFile; - - toFile = to.getPath() + COMPRESS_EXTENSION; - - File target = new File(toFile); - if (target.exists()) - { - LogLog.debug("deleting existing target file: " + target); - target.delete(); - } - - try - { - // Create the GZIP output stream - GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(target)); - try - { - // Open the input file - FileInputStream in = new FileInputStream(from); - try - { - // Transfer bytes from the input file to the GZIP output stream - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) - { - out.write(buf, 0, len); - } - } - finally - { - in.close(); - } - - // Complete the GZIP file - out.finish(); - } - finally - { - out.close(); - } - // Remove old file. - from.delete(); - } - catch (IOException e) - { - if (target.exists()) - { - target.delete(); - } - - rollFile(from.getPath(), to.getPath(), false); - } - } - - /** The default maximum file size is 10MB. */ - protected long getMaxFileSize() - { - return maxFileSize; - } - - /** How many sized based backups have been made so far */ - protected int getCurSizeRollBackups() - { - return curSizeRollBackups; - } - - protected void setCurSizeRollBackups(int curSizeRollBackups) - { - this.curSizeRollBackups = curSizeRollBackups; - } - - /** not yet implemented */ - protected int getMaxTimeRollBackups() - { - return maxTimeRollBackups; - } - - protected void setMaxTimeRollBackups(int maxTimeRollBackups) - { - this.maxTimeRollBackups = maxTimeRollBackups; - } - - protected int getCurTimeRollBackups() - { - return curTimeRollBackups; - } - - protected void setCurTimeRollBackups(int curTimeRollBackups) - { - this.curTimeRollBackups = curTimeRollBackups; - } - - protected boolean isRollDate() - { - return rollDate; - } - - protected void setRollDate(boolean rollDate) - { - this.rollDate = rollDate; - } - - protected boolean isRollSize() - { - return rollSize; - } - - protected void setRollSize(boolean rollSize) - { - this.rollSize = rollSize; - } - - /** - * By default file.log is always the current file. Optionally file.log.yyyy-mm-dd for current formated datePattern - * can by the currently logging file (or file.log.curSizeRollBackup or even file.log.yyyy-mm-dd.curSizeRollBackup) - * This will make time based roll overs with a large number of backups much faster -- it won't have to rename all - * the backups! - */ - protected boolean isStaticLogFileName() - { - return staticLogFileName; - } - - /** FileName provided in configuration. Used for rolling properly */ - protected String getBaseFileName() - { - return baseFileName; - } - - protected void setBaseFileName(String baseFileName) - { - this.baseFileName = baseFileName; - } - - /** Do we want to .gz our backup files. */ - protected boolean isCompress() - { - return compress; - } - - protected void setCompress(boolean compress) - { - this.compress = compress; - } - - /** Do we want to use a second thread when compressing our backup files. */ - protected boolean isCompressAsync() - { - return compressAsync; - } - - /** Do we want to start numbering files at zero. */ - protected boolean isZeroBased() - { - return zeroBased; - } - - protected void setBackupFilesToPath(String backupFilesToPath) - { - this.backupFilesToPath = backupFilesToPath; - } - - private static class CompressJob - { - private File _from, _to; - - CompressJob(File from, File to) - { - _from = from; - _to = to; - } - - File getFrom() - { - return _from; - } - - File getTo() - { - return _to; - } - } - - private Compressor compressor = null; - - private Executor executor; - - private class Compressor implements Runnable - { - public void run() - { - boolean running = true; - while (running) - { - CompressJob job = _compress.poll(); - - doCompress(job.getFrom(), job.getTo()); - - synchronized (_compress) - { - if (_compress.isEmpty()) - { - running = false; - _compressing.set(false); - } - } - } - - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java deleted file mode 100644 index 7de0ebe1de..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator; -import org.apache.qpid.server.configuration.store.ManagementModeStoreHandler; -import org.apache.qpid.server.logging.SystemOutMessageLogger; -import org.apache.qpid.server.logging.actors.BrokerActor; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.log4j.LoggingManagementFacade; -import org.apache.qpid.server.logging.messages.BrokerMessages; -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.registry.IApplicationRegistry; - -public class Broker -{ - private static final Logger LOGGER = Logger.getLogger(Broker.class); - - private volatile Thread _shutdownHookThread; - private volatile IApplicationRegistry _applicationRegistry; - - protected static class InitException extends RuntimeException - { - private static final long serialVersionUID = 1L; - - InitException(String msg, Throwable cause) - { - super(msg, cause); - } - } - - public void shutdown() - { - try - { - removeShutdownHook(); - } - finally - { - if (_applicationRegistry != null) - { - _applicationRegistry.close(); - } - - } - } - - public void startup() throws Exception - { - startup(new BrokerOptions()); - } - - public void startup(final BrokerOptions options) throws Exception - { - CurrentActor.set(new BrokerActor(new SystemOutMessageLogger())); - try - { - startupImpl(options); - addShutdownHook(); - } - finally - { - CurrentActor.remove(); - - } - } - - private void startupImpl(final BrokerOptions options) throws Exception - { - String storeLocation = options.getConfigurationStoreLocation(); - String storeType = options.getConfigurationStoreType(); - - CurrentActor.get().message(BrokerMessages.CONFIG(storeLocation)); - - //Allow skipping the logging configuration for people who are - //embedding the broker and want to configure it themselves. - if(!options.isSkipLoggingConfiguration()) - { - configureLogging(new File(options.getLogConfigFileLocation()), options.getLogWatchFrequency()); - } - - BrokerConfigurationStoreCreator storeCreator = new BrokerConfigurationStoreCreator(); - ConfigurationEntryStore store = storeCreator.createStore(storeLocation, storeType, options.getInitialConfigurationLocation(), - options.isOverwriteConfigurationStore(), options.getConfigProperties()); - - if (options.isManagementMode()) - { - store = new ManagementModeStoreHandler(store, options); - } - - _applicationRegistry = new ApplicationRegistry(store); - try - { - _applicationRegistry.initialise(options); - } - catch(Exception e) - { - try - { - _applicationRegistry.close(); - } - catch(Exception ce) - { - LOGGER.debug("An error occured when closing the registry following initialization failure", ce); - } - throw e; - } - - } - - public static void parsePortList(Set<Integer> output, List<?> ports) throws InitException - { - if(ports != null) - { - for(Object o : ports) - { - try - { - output.add(Integer.parseInt(String.valueOf(o))); - } - catch (NumberFormatException e) - { - throw new InitException("Invalid port: " + o, e); - } - } - } - } - - private void configureLogging(File logConfigFile, int logWatchTime) throws InitException, IOException - { - if (logConfigFile.exists() && logConfigFile.canRead()) - { - CurrentActor.get().message(BrokerMessages.LOG_CONFIG(logConfigFile.getAbsolutePath())); - - if (logWatchTime > 0) - { - System.out.println("log file " + logConfigFile.getAbsolutePath() + " will be checked for changes every " - + logWatchTime + " seconds"); - // log4j expects the watch interval in milliseconds - try - { - LoggingManagementFacade.configureAndWatch(logConfigFile.getPath(), logWatchTime * 1000); - } - catch (Exception e) - { - throw new InitException(e.getMessage(),e); - } - } - else - { - try - { - LoggingManagementFacade.configure(logConfigFile.getPath()); - } - catch (Exception e) - { - throw new InitException(e.getMessage(),e); - } - } - } - else - { - System.err.println("Logging configuration error: unable to read file " + logConfigFile.getAbsolutePath()); - System.err.println("Using the fallback internal fallback-log4j.properties configuration"); - - InputStream propsFile = this.getClass().getResourceAsStream("/fallback-log4j.properties"); - if(propsFile == null) - { - throw new IOException("Unable to load the fallback internal fallback-log4j.properties configuration file"); - } - else - { - try - { - Properties fallbackProps = new Properties(); - fallbackProps.load(propsFile); - PropertyConfigurator.configure(fallbackProps); - } - finally - { - propsFile.close(); - } - } - } - } - - - private void addShutdownHook() - { - Thread shutdownHookThread = new Thread(new ShutdownService()); - shutdownHookThread.setName("QpidBrokerShutdownHook"); - - Runtime.getRuntime().addShutdownHook(shutdownHookThread); - _shutdownHookThread = shutdownHookThread; - - LOGGER.debug("Added shutdown hook"); - } - - private void removeShutdownHook() - { - Thread shutdownThread = _shutdownHookThread; - - //if there is a shutdown thread and we aren't it, we should remove it - if(shutdownThread != null && !(Thread.currentThread() == shutdownThread)) - { - LOGGER.debug("Removing shutdown hook"); - - _shutdownHookThread = null; - - boolean removed = false; - try - { - removed = Runtime.getRuntime().removeShutdownHook(shutdownThread); - } - catch(IllegalStateException ise) - { - //ignore, means the JVM is already shutting down - } - - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("Removed shutdown hook: " + removed); - } - } - else - { - LOGGER.debug("Skipping shutdown hook removal as there either isnt one, or we are it."); - } - } - - public org.apache.qpid.server.model.Broker getBroker() - { - if (_applicationRegistry == null) - { - return null; - } - return _applicationRegistry.getBroker(); - } - - private class ShutdownService implements Runnable - { - public void run() - { - LOGGER.debug("Shutdown hook running"); - Broker.this.shutdown(); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java deleted file mode 100644 index d5f344f4ed..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java +++ /dev/null @@ -1,376 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server; - -import java.io.File; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.store.MemoryConfigurationEntryStore; -import org.apache.qpid.server.util.StringUtil; - -public class BrokerOptions -{ - /** - * Configuration property name for the absolute path to use for the broker work directory. - * - * If not otherwise set, the value for this configuration property defaults to the location - * set in the "QPID_WORK" system property if that was set, or the 'work' sub-directory of - * the JVM working directory ("user.dir" property) for the Java process if it was not. - */ - public static final String QPID_WORK_DIR = "qpid.work_dir"; - /** - * Configuration property name for the absolute path to use for the broker home directory. - * - * If not otherwise set, the value for this configuration property defaults to the location - * set in the "QPID_HOME" system property if that was set, or remains unset if it was not. - */ - public static final String QPID_HOME_DIR = "qpid.home_dir"; - public static final String QPID_AMQP_PORT = "qpid.amqp_port"; - public static final String QPID_HTTP_PORT = "qpid.http_port"; - public static final String QPID_RMI_PORT = "qpid.rmi_port"; - public static final String QPID_JMX_PORT = "qpid.jmx_port"; - - public static final String DEFAULT_AMQP_PORT_NUMBER = "5672"; - public static final String DEFAULT_HTTP_PORT_NUMBER = "8080"; - public static final String DEFAULT_RMI_PORT_NUMBER = "8999"; - public static final String DEFAULT_JMX_PORT_NUMBER = "9099"; - - public static final String DEFAULT_INITIAL_CONFIG_NAME = "initial-config.json"; - public static final String DEFAULT_STORE_TYPE = "json"; - public static final String DEFAULT_CONFIG_NAME_PREFIX = "config"; - public static final String DEFAULT_LOG_CONFIG_FILE = "etc/log4j.xml"; - public static final String DEFAULT_INITIAL_CONFIG_LOCATION = - BrokerOptions.class.getClassLoader().getResource(DEFAULT_INITIAL_CONFIG_NAME).toExternalForm(); - public static final String MANAGEMENT_MODE_USER_NAME = "mm_admin"; - private static final int MANAGEMENT_MODE_PASSWORD_LENGTH = 10; - - private static final File FALLBACK_WORK_DIR = new File(System.getProperty("user.dir"), "work"); - - private String _logConfigFile; - private Integer _logWatchFrequency = 0; - - private String _configurationStoreLocation; - private String _configurationStoreType; - - private String _initialConfigurationLocation; - - private boolean _managementMode; - private boolean _managementModeQuiesceVhosts; - private int _managementModeRmiPortOverride; - private int _managementModeJmxPortOverride; - private int _managementModeHttpPortOverride; - private String _managementModePassword; - private boolean _skipLoggingConfiguration; - private boolean _overwriteConfigurationStore; - private Map<String, String> _configProperties = new HashMap<String,String>(); - - public String getManagementModePassword() - { - if(_managementModePassword == null) - { - _managementModePassword = new StringUtil().randomAlphaNumericString(MANAGEMENT_MODE_PASSWORD_LENGTH); - } - - return _managementModePassword; - } - - public void setManagementModePassword(String managementModePassword) - { - _managementModePassword = managementModePassword; - } - - public int getLogWatchFrequency() - { - return _logWatchFrequency; - } - - /** - * Set the frequency with which the log config file will be checked for updates. - * @param logWatchFrequency frequency in seconds - */ - public void setLogWatchFrequency(final int logWatchFrequency) - { - _logWatchFrequency = logWatchFrequency; - } - - public boolean isManagementMode() - { - return _managementMode; - } - - public void setManagementMode(boolean managementMode) - { - _managementMode = managementMode; - } - - public boolean isManagementModeQuiesceVirtualHosts() - { - return _managementModeQuiesceVhosts; - } - - public void setManagementModeQuiesceVirtualHosts(boolean managementModeQuiesceVhosts) - { - _managementModeQuiesceVhosts = managementModeQuiesceVhosts; - } - - public int getManagementModeRmiPortOverride() - { - return _managementModeRmiPortOverride; - } - - public void setManagementModeRmiPortOverride(int managementModeRmiPortOverride) - { - _managementModeRmiPortOverride = managementModeRmiPortOverride; - } - - public int getManagementModeJmxPortOverride() - { - return _managementModeJmxPortOverride; - } - - public void setManagementModeJmxPortOverride(int managementModeJmxPortOverride) - { - _managementModeJmxPortOverride = managementModeJmxPortOverride; - } - - public int getManagementModeHttpPortOverride() - { - return _managementModeHttpPortOverride; - } - - public void setManagementModeHttpPortOverride(int managementModeHttpPortOverride) - { - _managementModeHttpPortOverride = managementModeHttpPortOverride; - } - - /** - * Get the broker configuration store type. - * - * @return the previously set store type, or if none was set the default: {@value #DEFAULT_STORE_TYPE} - */ - public String getConfigurationStoreType() - { - if(_configurationStoreType == null) - { - return DEFAULT_STORE_TYPE; - } - - return _configurationStoreType; - } - - /** - * Set the broker configuration store type. - * - * Passing null clears previously set values and returns to the default. - */ - public void setConfigurationStoreType(String cofigurationStoreType) - { - _configurationStoreType = cofigurationStoreType; - } - - /** - * Get the broker configuration store location. - * - * Defaults to {@value #DEFAULT_CONFIG_NAME_PREFIX}.{@literal <store type>} (see {@link BrokerOptions#getConfigurationStoreType()}) - * within the broker work directory (gathered via config property {@link #QPID_WORK_DIR}). - * - * @return the previously set configuration store location, or the default location if none was set. - */ - public String getConfigurationStoreLocation() - { - if(_configurationStoreLocation == null) - { - String workDir = getWorkDir(); - String storeType = getConfigurationStoreType(); - - return new File(workDir, DEFAULT_CONFIG_NAME_PREFIX + "." + storeType).getAbsolutePath(); - } - - return _configurationStoreLocation; - } - - /** - * Set the absolute path to use for the broker configuration store. - * - * Passing null clears any previously set value and returns to the default. - */ - public void setConfigurationStoreLocation(String cofigurationStore) - { - _configurationStoreLocation = cofigurationStore; - } - - /** - * Returns whether the existing broker configuration store should be overwritten with the current - * initial configuration file (see {@link BrokerOptions#getInitialConfigurationLocation()}). - */ - public boolean isOverwriteConfigurationStore() - { - return _overwriteConfigurationStore; - } - - /** - * Sets whether the existing broker configuration store should be overwritten with the current - * initial configuration file (see {@link BrokerOptions#getInitialConfigurationLocation()}). - */ - public void setOverwriteConfigurationStore(boolean overwrite) - { - _overwriteConfigurationStore = overwrite; - } - - /** - * Get the broker initial JSON configuration location. - * - * Defaults to an internal configuration file within the broker jar. - * - * @return the previously set configuration location, or the default location if none was set. - */ - public String getInitialConfigurationLocation() - { - if(_initialConfigurationLocation == null) - { - return DEFAULT_INITIAL_CONFIG_LOCATION; - } - - return _initialConfigurationLocation; - } - - /** - * Set the absolute path or URL to use for the initial JSON configuration, which is loaded with the - * {@link MemoryConfigurationEntryStore} in order to initialise any new {@link ConfigurationEntryStore} for the broker. - * - * Passing null clears any previously set value and returns to the default. - */ - public void setInitialConfigurationLocation(String initialConfigurationLocation) - { - _initialConfigurationLocation = initialConfigurationLocation; - } - - public boolean isSkipLoggingConfiguration() - { - return _skipLoggingConfiguration; - } - - public void setSkipLoggingConfiguration(boolean skipLoggingConfiguration) - { - _skipLoggingConfiguration = skipLoggingConfiguration; - } - - /** - * Sets the named configuration property to the given value. - * - * Passing a null value causes removal of a previous value, and restores any default there may have been. - */ - public void setConfigProperty(String name, String value) - { - if(value == null) - { - _configProperties.remove(name); - } - else - { - _configProperties.put(name, value); - } - } - - /** - * Get an un-editable copy of the configuration properties, representing - * the user-configured values as well as any defaults for properties - * not otherwise configured. - * - * Subsequent property changes are not reflected in this map. - */ - public Map<String,String> getConfigProperties() - { - ConcurrentHashMap<String, String> properties = new ConcurrentHashMap<String,String>(); - properties.putAll(_configProperties); - - properties.putIfAbsent(QPID_AMQP_PORT, String.valueOf(DEFAULT_AMQP_PORT_NUMBER)); - properties.putIfAbsent(QPID_HTTP_PORT, String.valueOf(DEFAULT_HTTP_PORT_NUMBER)); - properties.putIfAbsent(QPID_RMI_PORT, String.valueOf(DEFAULT_RMI_PORT_NUMBER)); - properties.putIfAbsent(QPID_JMX_PORT, String.valueOf(DEFAULT_JMX_PORT_NUMBER)); - properties.putIfAbsent(QPID_WORK_DIR, getWorkDir()); - - String homeDir = getHomeDir(); - if(homeDir != null) - { - properties.putIfAbsent(QPID_HOME_DIR, homeDir); - } - - return Collections.unmodifiableMap(properties); - } - - /** - * Get the broker logging configuration file location. - * - * If not previously explicitly set, defaults to {@value #DEFAULT_LOG_CONFIG_FILE} within the broker - * home directory if configured (gathered via config property {@link #QPID_HOME_DIR}) or the current - * JVM working directory if not. - * - * @return the previously set logging configuration file location, or the default location if none was set. - */ - public String getLogConfigFileLocation() - { - if(_logConfigFile == null) - { - String homeDir = getHomeDir(); - - return new File(homeDir, DEFAULT_LOG_CONFIG_FILE).getAbsolutePath(); - } - - return _logConfigFile; - } - - public void setLogConfigFileLocation(final String logConfigFile) - { - _logConfigFile = logConfigFile; - } - - private String getWorkDir() - { - if(!_configProperties.containsKey(QPID_WORK_DIR)) - { - String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK); - if (qpidWork == null) - { - return FALLBACK_WORK_DIR.getAbsolutePath(); - } - - return qpidWork; - } - - return _configProperties.get(QPID_WORK_DIR); - } - - private String getHomeDir() - { - if(!_configProperties.containsKey(QPID_HOME_DIR)) - { - return System.getProperty(BrokerProperties.PROPERTY_QPID_HOME); - } - - return _configProperties.get(QPID_HOME_DIR); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java deleted file mode 100644 index 20b73e965c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java +++ /dev/null @@ -1,381 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server; - -import java.io.File; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.cli.PosixParser; -import org.apache.log4j.Logger; -import org.apache.qpid.common.QpidProperties; -import org.apache.qpid.framing.ProtocolVersion; -import org.apache.qpid.server.configuration.store.ConfigurationEntryStoreUtil; - -/** - * Main entry point for AMQPD. - * - */ -public class Main -{ - private static final Option OPTION_HELP = new Option("h", "help", false, "print this message"); - - private static final Option OPTION_VERSION = new Option("v", "version", false, "print the version information and exit"); - - private static final Option OPTION_CONFIGURATION_STORE_PATH = OptionBuilder.withArgName("path").hasArg() - .withDescription("use given configuration store location").withLongOpt("store-path").create("sp"); - - private static final Option OPTION_CONFIGURATION_STORE_TYPE = OptionBuilder.withArgName("type").hasArg() - .withDescription("use given broker configuration store type").withLongOpt("store-type").create("st"); - - private static final Option OPTION_INITIAL_CONFIGURATION_PATH = OptionBuilder.withArgName("path").hasArg() - .withDescription("set the location of initial JSON config to use when creating/overwriting a broker configuration store").withLongOpt("initial-config-path").create("icp"); - - private static final Option OPTION_OVERWRITE_CONFIGURATION_STORE = OptionBuilder.withDescription("overwrite the broker configuration store with the current initial configuration") - .withLongOpt("overwrite-store").create("os"); - - private static final Option OPTION_CREATE_INITIAL_CONFIG = OptionBuilder.withArgName("path").hasOptionalArg().withDescription("create a copy of the initial config file, either to an" + - " optionally specified file path, or as " + BrokerOptions.DEFAULT_INITIAL_CONFIG_NAME + " in the current directory") - .withLongOpt("create-initial-config").create("cic"); - - private static final Option OPTION_CONFIGURATION_PROPERTY = OptionBuilder.withArgName("name=value").hasArg() - .withDescription("set a configuration property to use when resolving variables in the broker configuration store, with format \"name=value\"") - .withLongOpt("config-property").create("prop"); - - private static final Option OPTION_LOG_CONFIG_FILE = - OptionBuilder.withArgName("file").hasArg() - .withDescription("use the specified log4j xml configuration file. By " - + "default looks for a file named " + BrokerOptions.DEFAULT_LOG_CONFIG_FILE - + " in the same directory as the configuration file").withLongOpt("logconfig").create("l"); - - private static final Option OPTION_LOG_WATCH = - OptionBuilder.withArgName("period").hasArg() - .withDescription("monitor the log file configuration file for changes. Units are seconds. " - + "Zero means do not check for changes.").withLongOpt("logwatch").create("w"); - - private static final Option OPTION_MANAGEMENT_MODE = OptionBuilder.withDescription("start broker in management mode, disabling the AMQP ports") - .withLongOpt("management-mode").create("mm"); - private static final Option OPTION_MM_QUIESCE_VHOST = OptionBuilder.withDescription("make virtualhosts stay in the quiesced state during management mode.") - .withLongOpt("management-mode-quiesce-virtualhosts").create("mmqv"); - private static final Option OPTION_MM_RMI_PORT = OptionBuilder.withArgName("port").hasArg() - .withDescription("override jmx rmi registry port in management mode").withLongOpt("management-mode-rmi-registry-port").create("mmrmi"); - private static final Option OPTION_MM_CONNECTOR_PORT = OptionBuilder.withArgName("port").hasArg() - .withDescription("override jmx connector port in management mode").withLongOpt("management-mode-jmx-connector-port").create("mmjmx"); - private static final Option OPTION_MM_HTTP_PORT = OptionBuilder.withArgName("port").hasArg() - .withDescription("override http management port in management mode").withLongOpt("management-mode-http-port").create("mmhttp"); - private static final Option OPTION_MM_PASSWORD = OptionBuilder.withArgName("password").hasArg() - .withDescription("Set the password for the management mode user " + BrokerOptions.MANAGEMENT_MODE_USER_NAME).withLongOpt("management-mode-password").create("mmpass"); - - private static final Options OPTIONS = new Options(); - - static - { - OPTIONS.addOption(OPTION_HELP); - OPTIONS.addOption(OPTION_VERSION); - OPTIONS.addOption(OPTION_CONFIGURATION_STORE_PATH); - OPTIONS.addOption(OPTION_CONFIGURATION_STORE_TYPE); - OPTIONS.addOption(OPTION_OVERWRITE_CONFIGURATION_STORE); - OPTIONS.addOption(OPTION_CREATE_INITIAL_CONFIG); - OPTIONS.addOption(OPTION_LOG_CONFIG_FILE); - OPTIONS.addOption(OPTION_LOG_WATCH); - OPTIONS.addOption(OPTION_INITIAL_CONFIGURATION_PATH); - OPTIONS.addOption(OPTION_MANAGEMENT_MODE); - OPTIONS.addOption(OPTION_MM_QUIESCE_VHOST); - OPTIONS.addOption(OPTION_MM_RMI_PORT); - OPTIONS.addOption(OPTION_MM_CONNECTOR_PORT); - OPTIONS.addOption(OPTION_MM_HTTP_PORT); - OPTIONS.addOption(OPTION_MM_PASSWORD); - OPTIONS.addOption(OPTION_CONFIGURATION_PROPERTY); - } - - protected CommandLine _commandLine; - - public static void main(String[] args) - { - //if the -Dlog4j.configuration property has not been set, enable the init override - //to stop Log4J wondering off and picking up the first log4j.xml/properties file it - //finds from the classpath when we get the first Loggers - if(System.getProperty("log4j.configuration") == null) - { - System.setProperty("log4j.defaultInitOverride", "true"); - } - - new Main(args); - } - - public Main(final String[] args) - { - if (parseCommandline(args)) - { - try - { - execute(); - } - catch(Throwable e) - { - System.err.println("Exception during startup: " + e); - e.printStackTrace(); - shutdown(1); - } - } - } - - protected boolean parseCommandline(final String[] args) - { - try - { - _commandLine = new PosixParser().parse(OPTIONS, args); - - return true; - } - catch (ParseException e) - { - System.err.println("Error: " + e.getMessage()); - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("Qpid", OPTIONS, true); - - return false; - } - } - - protected void execute() throws Exception - { - BrokerOptions options = new BrokerOptions(); - String initialConfigLocation = _commandLine.getOptionValue(OPTION_INITIAL_CONFIGURATION_PATH.getOpt()); - if (initialConfigLocation != null) - { - options.setInitialConfigurationLocation(initialConfigLocation); - } - - //process the remaining options - if (_commandLine.hasOption(OPTION_HELP.getOpt())) - { - final HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("Qpid", OPTIONS, true); - } - else if (_commandLine.hasOption(OPTION_CREATE_INITIAL_CONFIG.getOpt())) - { - File destinationFile = null; - - String destinationOption = _commandLine.getOptionValue(OPTION_CREATE_INITIAL_CONFIG.getOpt()); - if (destinationOption != null) - { - destinationFile = new File(destinationOption); - } - else - { - destinationFile = new File(System.getProperty("user.dir"), BrokerOptions.DEFAULT_INITIAL_CONFIG_NAME); - } - - ConfigurationEntryStoreUtil util = new ConfigurationEntryStoreUtil(); - util.copyInitialConfigFile(options.getInitialConfigurationLocation(), destinationFile); - - System.out.println("Initial config written to: " + destinationFile.getAbsolutePath()); - } - else if (_commandLine.hasOption(OPTION_VERSION.getOpt())) - { - final StringBuilder protocol = new StringBuilder("AMQP version(s) [major.minor]: "); - boolean first = true; - for (final ProtocolVersion pv : ProtocolVersion.getSupportedProtocolVersions()) - { - if (first) - { - first = false; - } - else - { - protocol.append(", "); - } - - protocol.append(pv.getMajorVersion()).append('-').append(pv.getMinorVersion()); - } - System.out.println(QpidProperties.getVersionString() + " (" + protocol + ")"); - } - else - { - String[] configPropPairs = _commandLine.getOptionValues(OPTION_CONFIGURATION_PROPERTY.getOpt()); - if(configPropPairs != null && configPropPairs.length > 0) - { - for(String s : configPropPairs) - { - int firstEquals = s.indexOf("="); - if(firstEquals == -1) - { - throw new IllegalArgumentException("Configuration property argument is not of the format name=value: " + s); - } - String name = s.substring(0, firstEquals); - String value = s.substring(firstEquals + 1); - - if(name.equals("")) - { - throw new IllegalArgumentException("Configuration property argument is not of the format name=value: " + s); - } - - options.setConfigProperty(name, value); - } - } - - String configurationStore = _commandLine.getOptionValue(OPTION_CONFIGURATION_STORE_PATH.getOpt()); - if (configurationStore != null) - { - options.setConfigurationStoreLocation(configurationStore); - } - - String configurationStoreType = _commandLine.getOptionValue(OPTION_CONFIGURATION_STORE_TYPE.getOpt()); - if (configurationStoreType != null) - { - options.setConfigurationStoreType(configurationStoreType); - } - - String logWatchConfig = _commandLine.getOptionValue(OPTION_LOG_WATCH.getOpt()); - if(logWatchConfig != null) - { - options.setLogWatchFrequency(Integer.parseInt(logWatchConfig)); - } - - String logConfig = _commandLine.getOptionValue(OPTION_LOG_CONFIG_FILE.getOpt()); - if(logConfig != null) - { - options.setLogConfigFileLocation(logConfig); - } - - boolean overwriteConfigurationStore = _commandLine.hasOption(OPTION_OVERWRITE_CONFIGURATION_STORE.getOpt()); - options.setOverwriteConfigurationStore(overwriteConfigurationStore); - - boolean managementMode = _commandLine.hasOption(OPTION_MANAGEMENT_MODE.getOpt()); - if (managementMode) - { - options.setManagementMode(true); - String rmiPort = _commandLine.getOptionValue(OPTION_MM_RMI_PORT.getOpt()); - if (rmiPort != null) - { - options.setManagementModeRmiPortOverride(Integer.parseInt(rmiPort)); - } - String connectorPort = _commandLine.getOptionValue(OPTION_MM_CONNECTOR_PORT.getOpt()); - if (connectorPort != null) - { - options.setManagementModeJmxPortOverride(Integer.parseInt(connectorPort)); - } - String httpPort = _commandLine.getOptionValue(OPTION_MM_HTTP_PORT.getOpt()); - if (httpPort != null) - { - options.setManagementModeHttpPortOverride(Integer.parseInt(httpPort)); - } - - boolean quiesceVhosts = _commandLine.hasOption(OPTION_MM_QUIESCE_VHOST.getOpt()); - options.setManagementModeQuiesceVirtualHosts(quiesceVhosts); - - String password = _commandLine.getOptionValue(OPTION_MM_PASSWORD.getOpt()); - if (password != null) - { - options.setManagementModePassword(password); - } - } - setExceptionHandler(); - - startBroker(options); - } - } - - protected void setExceptionHandler() - { - Thread.UncaughtExceptionHandler handler = null; - String handlerClass = System.getProperty("qpid.broker.exceptionHandler"); - if(handlerClass != null) - { - try - { - handler = (Thread.UncaughtExceptionHandler) Class.forName(handlerClass).newInstance(); - } - catch (ClassNotFoundException e) - { - - } - catch (InstantiationException e) - { - - } - catch (IllegalAccessException e) - { - - } - catch (ClassCastException e) - { - - } - } - - if(handler == null) - { - handler = - new Thread.UncaughtExceptionHandler() - { - public void uncaughtException(final Thread t, final Throwable e) - { - boolean continueOnError = Boolean.getBoolean("qpid.broker.exceptionHandler.continue"); - try - { - System.err.println("########################################################################"); - System.err.println("#"); - System.err.print("# Unhandled Exception "); - System.err.print(e.toString()); - System.err.print(" in Thread "); - System.err.println(t.getName()); - System.err.println("#"); - System.err.println(continueOnError ? "# Forced to continue by JVM setting 'qpid.broker.exceptionHandler.continue'" : "# Exiting"); - System.err.println("#"); - System.err.println("########################################################################"); - e.printStackTrace(System.err); - - Logger logger = Logger.getLogger("org.apache.qpid.server.Main"); - logger.error("Uncaught exception, " + (continueOnError ? "continuing." : "shutting down."), e); - } - finally - { - if (!continueOnError) - { - Runtime.getRuntime().halt(1); - } - } - - } - }; - - Thread.setDefaultUncaughtExceptionHandler(handler); - } - } - - protected void startBroker(final BrokerOptions options) throws Exception - { - Broker broker = new Broker(); - broker.startup(options); - } - - protected void shutdown(final int status) - { - System.exit(status); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/TransactionTimeoutHelper.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/TransactionTimeoutHelper.java deleted file mode 100644 index b7007bf768..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/TransactionTimeoutHelper.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.logging.LogMessage; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.ChannelMessages; -import org.apache.qpid.server.txn.ServerTransaction; - -public class TransactionTimeoutHelper -{ - private static final String OPEN_TRANSACTION_TIMEOUT_ERROR = "Open transaction timed out"; - private static final String IDLE_TRANSACTION_TIMEOUT_ERROR = "Idle transaction timed out"; - - private final LogSubject _logSubject; - - private final CloseAction _closeAction; - - public TransactionTimeoutHelper(final LogSubject logSubject, final CloseAction closeAction) - { - _logSubject = logSubject; - _closeAction = closeAction; - } - - public void checkIdleOrOpenTimes(ServerTransaction transaction, long openWarn, long openClose, long idleWarn, long idleClose) throws AMQException - { - if (transaction.isTransactional()) - { - final long transactionUpdateTime = transaction.getTransactionUpdateTime(); - if(transactionUpdateTime > 0) - { - long idleTime = System.currentTimeMillis() - transactionUpdateTime; - boolean closed = logAndCloseIfNecessary(idleTime, idleWarn, idleClose, ChannelMessages.IDLE_TXN(idleTime), IDLE_TRANSACTION_TIMEOUT_ERROR); - if (closed) - { - return; // no point proceeding to check the open time - } - } - - final long transactionStartTime = transaction.getTransactionStartTime(); - if(transactionStartTime > 0) - { - long openTime = System.currentTimeMillis() - transactionStartTime; - logAndCloseIfNecessary(openTime, openWarn, openClose, ChannelMessages.OPEN_TXN(openTime), OPEN_TRANSACTION_TIMEOUT_ERROR); - } - } - } - - /** - * @return true iff closeTimeout was exceeded - */ - private boolean logAndCloseIfNecessary(final long timeSoFar, - final long warnTimeout, final long closeTimeout, - final LogMessage warnMessage, final String closeMessage) throws AMQException - { - if (isTimedOut(timeSoFar, warnTimeout)) - { - LogActor logActor = CurrentActor.get(); - logActor.message(_logSubject, warnMessage); - } - - if(isTimedOut(timeSoFar, closeTimeout)) - { - _closeAction.doTimeoutAction(closeMessage); - return true; - } - else - { - return false; - } - } - - private boolean isTimedOut(long timeSoFar, long timeout) - { - return timeout > 0L && timeSoFar > timeout; - } - - public interface CloseAction - { - void doTimeoutAction(String reason) throws AMQException; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/binding/Binding.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/binding/Binding.java deleted file mode 100644 index 469a4bb9d0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/binding/Binding.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.binding; - -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.queue.AMQQueue; - -import java.util.Collections; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicLong; - -public class Binding -{ - private final String _bindingKey; - private final AMQQueue _queue; - private final Exchange _exchange; - private final Map<String, Object> _arguments; - private final UUID _id; - private final AtomicLong _matches = new AtomicLong(); - - public Binding(UUID id, - final String bindingKey, - final AMQQueue queue, - final Exchange exchange, - final Map<String, Object> arguments) - { - _id = id; - _bindingKey = bindingKey; - _queue = queue; - _exchange = exchange; - _arguments = arguments == null ? Collections.EMPTY_MAP : Collections.unmodifiableMap(arguments); - } - - public UUID getId() - { - return _id; - } - - public String getBindingKey() - { - return _bindingKey; - } - - public AMQQueue getQueue() - { - return _queue; - } - - public Exchange getExchange() - { - return _exchange; - } - - public Map<String, Object> getArguments() - { - return _arguments; - } - - public void incrementMatches() - { - _matches.incrementAndGet(); - } - - public long getMatches() - { - return _matches.get(); - } - - boolean isDurable() - { - return _queue.isDurable() && _exchange.isDurable(); - } - - @Override - public boolean equals(final Object o) - { - if (this == o) - { - return true; - } - - if (!(o instanceof Binding)) - { - return false; - } - - final Binding binding = (Binding) o; - - return (_bindingKey == null ? binding.getBindingKey() == null : _bindingKey.equals(binding.getBindingKey())) - && (_exchange == null ? binding.getExchange() == null : _exchange.equals(binding.getExchange())) - && (_queue == null ? binding.getQueue() == null : _queue.equals(binding.getQueue())); - } - - @Override - public int hashCode() - { - int result = _bindingKey == null ? 1 : _bindingKey.hashCode(); - result = 31 * result + (_queue == null ? 3 : _queue.hashCode()); - result = 31 * result + (_exchange == null ? 5 : _exchange.hashCode()); - return result; - } - - public String toString() - { - return "Binding{bindingKey="+_bindingKey+", exchange="+_exchange+", queue="+_queue+", id= " + _id + " }"; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java deleted file mode 100644 index 2d42d60039..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.qpid.server.configuration.store.MemoryConfigurationEntryStore; -import org.apache.qpid.server.plugin.ConfigurationStoreFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -/** - * A helper class responsible for creation and opening of broker store. - */ -public class BrokerConfigurationStoreCreator -{ - private Map<String, ConfigurationStoreFactory> _factories = new HashMap<String, ConfigurationStoreFactory>(); - - public BrokerConfigurationStoreCreator() - { - QpidServiceLoader<ConfigurationStoreFactory> serviceLoader = new QpidServiceLoader<ConfigurationStoreFactory>(); - Iterable<ConfigurationStoreFactory> configurationStoreFactories = serviceLoader - .instancesOf(ConfigurationStoreFactory.class); - for (ConfigurationStoreFactory storeFactory : configurationStoreFactories) - { - String type = storeFactory.getType(); - ConfigurationStoreFactory factory = _factories.put(type.toLowerCase(), storeFactory); - if (factory != null) - { - throw new IllegalStateException("ConfigurationStoreFactory with type name '" + type - + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '" - + storeFactory.getClass().getName() + "'"); - } - } - } - - /** - * Create broker configuration store for a given store location, store type, initial json config location - * - * @param storeLocation store location - * @param storeType store type - * @param initialConfigLocation initial store location - * @param overwrite whether to overwrite an existing configuration store with the initial configuration - * @param configProperties a map of configuration properties the store can use to resolve configuration variables - * @throws IllegalConfigurationException if store type is unknown - */ - public ConfigurationEntryStore createStore(String storeLocation, String storeType, String initialConfigLocation, boolean overwrite, Map<String, String> configProperties) - { - ConfigurationEntryStore initialStore = new MemoryConfigurationEntryStore(initialConfigLocation, null, configProperties); - ConfigurationStoreFactory factory = _factories.get(storeType.toLowerCase()); - if (factory == null) - { - throw new IllegalConfigurationException("Unknown store type: " + storeType); - } - return factory.createStore(storeLocation, initialStore, overwrite, configProperties); - } - - public Collection<String> getStoreTypes() - { - return Collections.unmodifiableCollection(_factories.keySet()); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java deleted file mode 100644 index fb382a8ca9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import java.util.Locale; - -/** - * Declares broker system property names - */ -public class BrokerProperties -{ - public static final int DEFAULT_HEARTBEAT_TIMEOUT_FACTOR = 2; - public static final String PROPERTY_HEARTBEAT_TIMEOUT_FACTOR = "qpid.broker_heartbeat_timeout_factor"; - public static final int HEARTBEAT_TIMEOUT_FACTOR = Integer.getInteger(PROPERTY_HEARTBEAT_TIMEOUT_FACTOR, DEFAULT_HEARTBEAT_TIMEOUT_FACTOR); - - public static final String PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX = "qpid.broker_dead_letter_exchange_suffix"; - public static final String PROPERTY_DEAD_LETTER_QUEUE_SUFFIX = "qpid.broker_dead_letter_queue_suffix"; - - public static final String PROPERTY_MSG_AUTH = "qpid.broker_msg_auth"; - public static final String PROPERTY_STATUS_UPDATES = "qpid.broker_status_updates"; - public static final String PROPERTY_LOCALE = "qpid.broker_locale"; - public static final String PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY = "qpid.broker_default_supported_protocol_version_reply"; - public static final String PROPERTY_DISABLED_FEATURES = "qpid.broker_disabled_features"; - - private static final int DEFAULT_FRAME_SIZE = 65535; - public static final String PROPERTY_FRAME_SIZE = "qpid.broker_frame_size"; - public static final int FRAME_SIZE = Integer.getInteger(PROPERTY_FRAME_SIZE, DEFAULT_FRAME_SIZE); - - public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES = "qpid.broker_default_amqp_protocol_excludes"; - public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES = "qpid.broker_default_amqp_protocol_includes"; - - public static final String PROPERTY_MANAGEMENT_RIGHTS_INFER_ALL_ACCESS = "qpid.broker_jmx_method_rights_infer_all_access"; - public static final String PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY = "qpid.broker_jmx_use_custom_rmi_socket_factory"; - - public static final String PROPERTY_DEFAULT_SHARED_MESSAGE_GROUP = "qpid.broker_default-shared-message-group"; - - public static final String PROPERTY_QPID_HOME = "QPID_HOME"; - public static final String PROPERTY_QPID_WORK = "QPID_WORK"; - public static final String PROPERTY_LOG_RECORDS_BUFFER_SIZE = "qpid.broker_log_records_buffer_size"; - - private BrokerProperties() - { - } - - public static Locale getLocale() - { - Locale locale = Locale.US; - String localeSetting = System.getProperty(BrokerProperties.PROPERTY_LOCALE); - if (localeSetting != null) - { - String[] localeParts = localeSetting.split("_"); - String language = (localeParts.length > 0 ? localeParts[0] : ""); - String country = (localeParts.length > 1 ? localeParts[1] : ""); - String variant = ""; - if (localeParts.length > 2) - { - variant = localeSetting.substring(language.length() + 1 + country.length() + 1); - } - locale = new Locale(language, country, variant); - } - return locale; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java deleted file mode 100644 index 8afb1af24d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -public class ConfigurationEntry -{ - public static final String ATTRIBUTE_NAME = "name"; - - private final UUID _id; - private final String _type; - private final Map<String, Object> _attributes; - private final Set<UUID> _childrenIds; - private final ConfigurationEntryStore _store; - - public ConfigurationEntry(UUID id, String type, Map<String, Object> attributes, Set<UUID> childrenIds, - ConfigurationEntryStore store) - { - super(); - _id = id; - _type = type; - _attributes = attributes; - _childrenIds = childrenIds; - _store = store; - } - - public UUID getId() - { - return _id; - } - - public String getType() - { - return _type; - } - - public Map<String, Object> getAttributes() - { - return _attributes; - } - - public Set<UUID> getChildrenIds() - { - return _childrenIds; - } - - public ConfigurationEntryStore getStore() - { - return _store; - } - - /** - * Returns this entry's children. The collection should not be modified. - */ - public Map<String, Collection<ConfigurationEntry>> getChildren() - { - Map<String, Collection<ConfigurationEntry>> children = null; - if (_childrenIds == null) - { - children = Collections.emptyMap(); - } - else - { - children = new HashMap<String, Collection<ConfigurationEntry>>(); - for (UUID childId : _childrenIds) - { - ConfigurationEntry entry = _store.getEntry(childId); - String type = entry.getType(); - Collection<ConfigurationEntry> childrenOfType = children.get(type); - if (childrenOfType == null) - { - childrenOfType = new ArrayList<ConfigurationEntry>(); - children.put(type, childrenOfType); - } - childrenOfType.add(entry); - } - } - return Collections.unmodifiableMap(children); - } - - public boolean hasChild(UUID id) - { - return _childrenIds.contains(id); - } - - @Override - public int hashCode() - { - return _id.hashCode(); - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - - ConfigurationEntry other = (ConfigurationEntry) obj; - if (_id == null) - { - if (other._id != null) - { - return false; - } - } - else if (!_id.equals(other._id)) - { - return false; - } - - if (_type == null) - { - if (other._type != null) - { - return false; - } - } - else if (!_type.equals(other._type)) - { - return false; - } - - if (_store == null) - { - if (other._store != null) - { - return false; - } - } - else if (!_store.equals(other._store)) - { - return false; - } - - if (_childrenIds == null) - { - if (other._childrenIds != null) - { - return false; - } - } - else if (!_childrenIds.equals(other._childrenIds)) - { - return false; - } - - if (_attributes == null) - { - if (other._attributes != null) - { - return false; - } - } - else if (!_attributes.equals(other._attributes)) - { - return false; - } - return true; - } - - @Override - public String toString() - { - return "ConfigurationEntry [id=" + _id + ", type=" + _type + ", attributes=" + _attributes + ", childrenIds=" - + _childrenIds + "]"; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java deleted file mode 100644 index 5f3589c7ef..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import java.util.UUID; - -public interface ConfigurationEntryStore -{ - - /** - * Returns stored root configuration entry - * - * @return root entry - */ - ConfigurationEntry getRootEntry(); - - /** - * Returns the configuration entry with a given id. - * - * @return entry with a given id or null if entry does not exists - */ - ConfigurationEntry getEntry(UUID id); - - /** - * Saves given entries in the store. - * - * @param entries entries to store - * @throws IllegalConfigurationException if save operation fails - */ - void save(ConfigurationEntry... entries); - - /** - * Removes the entries with given IDs and all their children - * - * @param entryIds IDs of entries to remove - * @return IDs of removed entries - * @throws IllegalConfigurationException if remove operation fails - */ - UUID[] remove(UUID... entryIds); - - /** - * Copies the store into the given location - * - * @param target location to copy store into - * @throws IllegalConfigurationException if store cannot be copied into given location - */ - void copyTo(String copyLocation); - - /** - * Return the store location for the opened store or null if store has not been opened. - * - * @return store location for the opened store or null if store has not been opened - */ - String getStoreLocation(); - - /** - * Returns the version of the store - * - * @return store version - */ - int getVersion(); - - /** - * Returns the type of the store - * - * @return store type - */ - String getType(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java deleted file mode 100644 index 65d97e6db1..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import org.apache.qpid.server.model.ConfiguredObject; - -public interface ConfiguredObjectRecoverer<T extends ConfiguredObject> -{ - T create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfiguration.java deleted file mode 100644 index c7cf0c0892..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfiguration.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import org.apache.commons.configuration.Configuration; - - -public class ExchangeConfiguration -{ - - private Configuration _config; - private String _name; - - public ExchangeConfiguration(String exchName, Configuration subset) - { - _name = exchName; - _config = subset; - } - - public String getName() - { - return _name; - } - - public String getType() - { - return _config.getString("type","direct"); - } - - public boolean getDurable() - { - return _config.getBoolean("durable", false); - } - - public boolean getAutoDelete() - { - return _config.getBoolean("autodelete",false); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java deleted file mode 100644 index bedd470ddf..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -public class IllegalConfigurationException extends RuntimeException -{ - private static final long serialVersionUID = 1130064756291179812L; - - public IllegalConfigurationException(String message) - { - super(message); - } - - public IllegalConfigurationException(String message, Throwable cause) - { - super(message, cause); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java deleted file mode 100644 index 25466d9c55..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import java.util.Collections; -import java.util.Map; -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; - -import java.util.List; - -public class QueueConfiguration extends AbstractConfiguration -{ - private String _name; - private VirtualHostConfiguration _vHostConfig; - - public QueueConfiguration(String name, VirtualHostConfiguration virtualHostConfiguration) throws ConfigurationException - { - _vHostConfig = virtualHostConfiguration; - _name = name; - - CompositeConfiguration mungedConf = new CompositeConfiguration(); - mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + escapeTagName(name))); - mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues")); - - setConfiguration("virtualhosts.virtualhost.queues.queue", mungedConf); - } - - public String[] getElementsProcessed() - { - return new String[]{"maximumMessageSize", - "maximumQueueDepth", - "maximumMessageCount", - "maximumMessageAge", - "minimumAlertRepeatGap", - "durable", - "exchange", - "exclusive", - "queue", - "autodelete", - "priority", - "priorities", - "routingKey", - "capacity", - "flowResumeCapacity", - "lvq", - "lvqKey", - "sortKey", - "maximumDeliveryCount", - "deadLetterQueues", - "argument" - }; - } - - @Override - public void validateConfiguration() throws ConfigurationException - { - //Currently doesn't do validation - } - - public VirtualHostConfiguration getVirtualHostConfiguration() - { - return _vHostConfig; - } - - public boolean getDurable() - { - return getBooleanValue("durable"); - } - - public boolean getExclusive() - { - return getBooleanValue("exclusive"); - } - - public boolean getAutoDelete() - { - return getBooleanValue("autodelete"); - } - - public String getOwner() - { - return getStringValue("owner", null); - } - - public boolean getPriority() - { - return getBooleanValue("priority"); - } - - public int getPriorities() - { - return getIntValue("priorities", -1); - } - - public String getExchange() - { - return getStringValue("exchange", ExchangeDefaults.DEFAULT_EXCHANGE_NAME); - } - - public List getRoutingKeys() - { - return getListValue("routingKey"); - } - - public String getName() - { - return _name; - } - - public String getDescription() - { - return getStringValue("description"); - } - - public int getMaximumMessageAge() - { - return getIntValue("maximumMessageAge", _vHostConfig.getMaximumMessageAge()); - } - - public long getMaximumQueueDepth() - { - return getLongValue("maximumQueueDepth", _vHostConfig.getMaximumQueueDepth()); - } - - public long getMaximumMessageSize() - { - return getLongValue("maximumMessageSize", _vHostConfig.getMaximumMessageSize()); - } - - public long getMaximumMessageCount() - { - return getLongValue("maximumMessageCount", _vHostConfig.getMaximumMessageCount()); - } - - public long getMinimumAlertRepeatGap() - { - return getLongValue("minimumAlertRepeatGap", _vHostConfig.getMinimumAlertRepeatGap()); - } - - public long getCapacity() - { - return getLongValue("capacity", _vHostConfig.getCapacity()); - } - - public long getFlowResumeCapacity() - { - return getLongValue("flowResumeCapacity", _vHostConfig.getFlowResumeCapacity()); - } - - public boolean isLVQ() - { - return getBooleanValue("lvq"); - } - - public String getLVQKey() - { - return getStringValue("lvqKey", null); - } - - public String getQueueSortKey() - { - return getStringValue("sortKey", null); - } - - public int getMaxDeliveryCount() - { - return getIntValue("maximumDeliveryCount", _vHostConfig.getMaxDeliveryCount()); - } - - /** - * Check if dead letter queue delivery is enabled, deferring to the virtualhost configuration if not set. - */ - public boolean isDeadLetterQueueEnabled() - { - return getBooleanValue("deadLetterQueues", _vHostConfig.isDeadLetterQueueEnabled()); - } - - public Map<String,String> getArguments() - { - return getMap("argument"); - } - - public Map<String,String> getBindingArguments(String routingKey) - { - - return getConfig().containsKey(routingKey+".bindingArgument") ? getMap(routingKey+".bindingArgument") : null; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java deleted file mode 100644 index 963d019ec3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import org.apache.qpid.server.model.ConfiguredObject; - -public interface RecovererProvider -{ - ConfiguredObjectRecoverer<? extends ConfiguredObject> getRecoverer(String type); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java deleted file mode 100644 index 189f5916e0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; -import org.apache.qpid.server.model.Broker; - -import java.io.File; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -public class VirtualHostConfiguration extends AbstractConfiguration -{ - private final String _name; - private final Map<String, QueueConfiguration> _queues = new HashMap<String, QueueConfiguration>(); - private final Map<String, ExchangeConfiguration> _exchanges = new HashMap<String, ExchangeConfiguration>(); - private final Broker _broker; - private final long _defaultHouseKeepingCheckPeriod; - - public VirtualHostConfiguration(String name, Configuration config, Broker broker) throws ConfigurationException - { - _name = name; - _broker = broker; - - // store value of this attribute for running life of virtual host since updating of this value has no run-time effect - _defaultHouseKeepingCheckPeriod = ((Number)_broker.getAttribute(Broker.VIRTUALHOST_HOUSEKEEPING_CHECK_PERIOD)).longValue(); - setConfiguration(config); - } - - public VirtualHostConfiguration(String name, File configurationFile, Broker broker) throws ConfigurationException - { - this(name, loadConfiguration(name, configurationFile), broker); - } - - private static Configuration loadConfiguration(String name, File configurationFile) throws ConfigurationException - { - Configuration configuration = null; - if (configurationFile == null) - { - throw new IllegalConfigurationException("Virtualhost configuration file must be supplied!"); - } - else - { - Configuration virtualHostConfig = XmlConfigurationUtilities.parseConfig(configurationFile); - - // check for the element with the same name as virtual host - Configuration config = virtualHostConfig.subset("virtualhost." + XmlConfigurationUtilities.escapeTagName(name)); - if (config.isEmpty()) - { - throw new IllegalConfigurationException("No configuration found for virtual host '" + name + "' in " + configurationFile.getAbsolutePath()); - } - else - { - configuration = config; - } - } - return configuration; - } - - /** - * Apply the given configuration to this VirtualHostConfiguration - * - * @param config the config to apply - * @throws ConfigurationException if a problem occurs with configuration - */ - public void setConfiguration(Configuration config) throws ConfigurationException - { - setConfiguration("virtualhosts.virtualhost", config); - - Iterator i = getListValue("queues.queue.name").iterator(); - - while (i.hasNext()) - { - String queueName = (String) i.next(); - _queues.put(queueName, new QueueConfiguration(queueName, this)); - } - - i = getListValue("exchanges.exchange.name").iterator(); - int count = 0; - while (i.hasNext()) - { - CompositeConfiguration mungedConf = new CompositeConfiguration(); - mungedConf.addConfiguration(config.subset("exchanges.exchange(" + count++ + ")")); - mungedConf.addConfiguration(getConfig().subset("exchanges")); - String exchName = (String) i.next(); - _exchanges.put(exchName, new ExchangeConfiguration(exchName, mungedConf)); - } - } - - public String getName() - { - return _name; - } - - public long getHousekeepingCheckPeriod() - { - return getLongValue("housekeeping.checkPeriod", _defaultHouseKeepingCheckPeriod); - } - - public Configuration getStoreConfiguration() - { - return getConfig().subset("store"); - } - - public String getMessageStoreClass() - { - return getStringValue("store.class", null); - } - - public void setMessageStoreClass(String storeFactoryClass) - { - getConfig().setProperty("store.class", storeFactoryClass); - } - - public List getExchanges() - { - return getListValue("exchanges.exchange.name"); - } - - public String[] getQueueNames() - { - return _queues.keySet().toArray(new String[_queues.size()]); - } - - public ExchangeConfiguration getExchangeConfiguration(String exchangeName) - { - return _exchanges.get(exchangeName); - } - - public QueueConfiguration getQueueConfiguration(String queueName) - { - // We might be asked for the config for a queue we don't know about, - // such as one that's been dynamically created. Those get the defaults by default. - if (_queues.containsKey(queueName)) - { - return _queues.get(queueName); - } - else - { - try - { - return new QueueConfiguration(queueName, this); - } - catch (ConfigurationException e) - { - // The configuration is empty so there can't be an error. - return null; - } - } - } - - public int getMaximumMessageAge() - { - return getIntValue("queues.maximumMessageAge", getBrokerAttributeAsInt(Broker.QUEUE_ALERT_THRESHOLD_MESSAGE_AGE)); - } - - public Long getMaximumQueueDepth() - { - return getLongValue("queues.maximumQueueDepth", getBrokerAttributeAsLong(Broker.QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES)); - } - - public Long getMaximumMessageSize() - { - return getLongValue("queues.maximumMessageSize", getBrokerAttributeAsLong(Broker.QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE)); - } - - public Long getMaximumMessageCount() - { - return getLongValue("queues.maximumMessageCount", getBrokerAttributeAsLong(Broker.QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES)); - } - - public Long getMinimumAlertRepeatGap() - { - return getLongValue("queues.minimumAlertRepeatGap", getBrokerAttributeAsLong(Broker.QUEUE_ALERT_REPEAT_GAP)); - } - - public long getCapacity() - { - return getLongValue("queues.capacity", getBrokerAttributeAsLong(Broker.QUEUE_FLOW_CONTROL_SIZE_BYTES)); - } - - public long getFlowResumeCapacity() - { - return getLongValue("queues.flowResumeCapacity", getBrokerAttributeAsLong(Broker.QUEUE_FLOW_CONTROL_RESUME_SIZE_BYTES)); - } - - public String[] getElementsProcessed() - { - return new String[]{"queues", "exchanges", "custom-exchanges", "store", "housekeeping"}; - - } - - @Override - public void validateConfiguration() throws ConfigurationException - { - // QPID-3249. Support for specifying authentication name at vhost level is no longer supported. - if (getListValue("security.authentication.name").size() > 0) - { - String message = "Validation error : security/authentication/name is no longer a supported element within the configuration xml." - + " It appears in virtual host definition : " + _name; - throw new ConfigurationException(message); - } - - // QPID-3266. Tidy up housekeeping configuration option for scheduling frequency - if (contains("housekeeping.expiredMessageCheckPeriod")) - { - String message = "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod." - + " It appears in virtual host definition : " + _name; - throw new ConfigurationException(message); - } - } - - public int getHouseKeepingThreadCount() - { - return getIntValue("housekeeping.poolSize", Runtime.getRuntime().availableProcessors()); - } - - public long getTransactionTimeoutOpenWarn() - { - return getLongValue("transactionTimeout.openWarn", - getBrokerAttributeAsLong(Broker.VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_WARN)); - } - - public long getTransactionTimeoutOpenClose() - { - return getLongValue("transactionTimeout.openClose", - getBrokerAttributeAsLong(Broker.VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE)); - } - - public long getTransactionTimeoutIdleWarn() - { - return getLongValue("transactionTimeout.idleWarn", - getBrokerAttributeAsLong(Broker.VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_WARN)); - } - - public long getTransactionTimeoutIdleClose() - { - return getLongValue("transactionTimeout.idleClose", - getBrokerAttributeAsLong(Broker.VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE)); - } - - public int getMaxDeliveryCount() - { - return getIntValue("queues.maximumDeliveryCount", getBrokerAttributeAsInt(Broker.QUEUE_MAXIMUM_DELIVERY_ATTEMPTS)); - } - - /** - * Check if dead letter queue delivery is enabled, deferring to the broker configuration if not set. - */ - public boolean isDeadLetterQueueEnabled() - { - return getBooleanValue("queues.deadLetterQueues", getBrokerAttributeAsBoolean(Broker.QUEUE_DEAD_LETTER_QUEUE_ENABLED)); - } - - private long getBrokerAttributeAsLong(String name) - { - Number brokerValue = (Number)_broker.getAttribute(name); - return brokerValue == null? 0 : brokerValue.longValue(); - } - - private int getBrokerAttributeAsInt(String name) - { - Number brokerValue = (Number)_broker.getAttribute(name); - return brokerValue == null? 0 : brokerValue.intValue(); - } - - private boolean getBrokerAttributeAsBoolean(String name) - { - Boolean brokerValue = (Boolean)_broker.getAttribute(name); - return brokerValue == null? false : brokerValue.booleanValue(); - } - - public String getType() - { - return getStringValue("type", "org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore".equals(getMessageStoreClass()) ? "BDB_HA": "STANDARD"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java deleted file mode 100644 index 84972c1e0a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration; - -import java.io.File; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.ConfigurationFactory; -import org.apache.commons.configuration.SystemConfiguration; -import org.apache.commons.configuration.XMLConfiguration; - -public class XmlConfigurationUtilities -{ - - // Our configuration class needs to make the interpolate method - // public so it can be called below from the config method. - public static class MyConfiguration extends CompositeConfiguration - { - public String interpolate(String obj) - { - return super.interpolate(obj); - } - } - - public static Configuration parseConfig(File file) throws ConfigurationException - { - ConfigurationFactory factory = new ConfigurationFactory(); - factory.setConfigurationFileName(file.getAbsolutePath()); - Configuration conf = factory.getConfiguration(); - - Iterator<?> keys = conf.getKeys(); - if (!keys.hasNext()) - { - keys = null; - conf = flatConfig(file); - } - - return conf; - } - - public final static Configuration flatConfig(File file) throws ConfigurationException - { - // We have to override the interpolate methods so that - // interpolation takes place across the entirety of the - // composite configuration. Without doing this each - // configuration object only interpolates variables defined - // inside itself. - final MyConfiguration conf = new MyConfiguration(); - conf.addConfiguration(new SystemConfiguration() - { - protected String interpolate(String o) - { - return conf.interpolate(o); - } - }); - conf.addConfiguration(new XMLConfiguration(file) - { - protected String interpolate(String o) - { - return conf.interpolate(o); - } - }); - return conf; - } - - public static String escapeTagName(String name) - { - return name.replaceAll("\\.", "\\.\\."); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java deleted file mode 100644 index b87022868e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.plugins; - -import java.util.LinkedHashMap; -import java.util.Map; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.ConversionException; -import org.apache.log4j.Logger; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Set; - -public abstract class AbstractConfiguration -{ - protected static final Logger _logger = Logger.getLogger(AbstractConfiguration.class); - - private Configuration _config; - - /** - * The Elements that this Plugin can process. - * - * For a Queues plugin that would be a list containing: - * <ul> - * <li>queue - the queue entries - * <li>the alerting values for defaults - * <li>exchange - the default exchange - * <li>durable - set the default durablity - * </ul> - */ - abstract public String[] getElementsProcessed(); - - /** Performs configuration validation. */ - public void validateConfiguration() throws ConfigurationException - { - // Override in sub-classes - } - - public Configuration getConfig() - { - return _config; - } - - /** - * Sets the configuration for this plugin - * - * @param path - * @param configuration the configuration for this plugin. - */ - public void setConfiguration(String path, Configuration configuration) throws ConfigurationException - { - _config = configuration; - - // Extract a list of elements for processing - Iterator<?> keys = configuration.getKeys(); - - Set<String> elements = new HashSet<String>(); - while (keys.hasNext()) - { - String key = (String) keys.next(); - - int elementNameIndex = key.indexOf("."); - - String element = key.trim(); - if (elementNameIndex != -1) - { - element = key.substring(0, elementNameIndex).trim(); - } - - // Trim any element properties - elementNameIndex = element.indexOf("["); - if (elementNameIndex > 0) - { - element = element.substring(0, elementNameIndex).trim(); - } - - elements.add(element); - } - - //Remove the items we already expect in the configuration - for (String tag : getElementsProcessed()) - { - - // Work round the issue with Commons configuration. - // With an XMLConfiguration the key will be [@property] - // but with a CompositeConfiguration it will be @property]. - // Hide this issue from our users so when/if we change the - // configuration they don't have to. - int bracketIndex = tag.indexOf("["); - if (bracketIndex != -1) - { - tag = tag.substring(bracketIndex + 1, tag.length()); - } - - elements.remove(tag); - } - - if (_logger.isInfoEnabled()) - { - if (!elements.isEmpty()) - { - _logger.info("Elements to lookup:" + path); - for (String tag : elements) - { - _logger.info("Tag:'" + tag + "'"); - } - } - } - - validateConfiguration(); - } - - /** Helper method to print out list of keys in a {@link Configuration}. */ - public static final void showKeys(Configuration config) - { - if (config.isEmpty()) - { - _logger.info("Configuration is empty"); - } - else - { - Iterator<?> keys = config.getKeys(); - while (keys.hasNext()) - { - String key = (String) keys.next(); - _logger.info("Configuration key: " + key); - } - } - } - - protected boolean hasConfiguration() - { - return _config != null; - } - - /// Getters - - protected double getDoubleValue(String property) - { - return getDoubleValue(property, 0.0); - } - - protected double getDoubleValue(String property, double defaultValue) - { - return _config.getDouble(property, defaultValue); - } - - protected long getLongValue(String property) - { - return getLongValue(property, 0); - } - - protected long getLongValue(String property, long defaultValue) - { - return _config.getLong(property, defaultValue); - } - - protected int getIntValue(String property) - { - return getIntValue(property, 0); - } - - protected int getIntValue(String property, int defaultValue) - { - return _config.getInt(property, defaultValue); - } - - protected String getStringValue(String property) - { - return getStringValue(property, null); - } - - protected String getStringValue(String property, String defaultValue) - { - return _config.getString(property, defaultValue); - } - - protected boolean getBooleanValue(String property) - { - return getBooleanValue(property, false); - } - - protected boolean getBooleanValue(String property, boolean defaultValue) - { - return _config.getBoolean(property, defaultValue); - } - - protected List getListValue(String property) - { - return getListValue(property, Collections.EMPTY_LIST); - } - - protected List getListValue(String property, List defaultValue) - { - return _config.getList(property, defaultValue); - } - - /// Validation Helpers - - protected boolean contains(String property) - { - return _config.getProperty(property) != null; - } - - /** - * Provide mechanism to validate Configuration contains a Postiive Long Value - * - * @param property - * - * @throws ConfigurationException - */ - protected void validatePositiveLong(String property) throws ConfigurationException - { - try - { - if (!containsPositiveLong(property)) - { - throw new ConfigurationException(this.getClass().getSimpleName() - + ": '" + property + - "' must be a Positive Long value."); - } - } - catch (Exception e) - { - Throwable last = e; - - // Find the first cause - if (e instanceof ConversionException) - { - Throwable t = e.getCause(); - while (t != null) - { - last = t; - t = last.getCause(); - } - } - - throw new ConfigurationException(this.getClass().getSimpleName() + - ": unable to configure invalid " + - property + ":" + - _config.getString(property), - last); - } - } - - protected boolean containsLong(String property) - { - try - { - _config.getLong(property); - return true; - } - catch (NoSuchElementException e) - { - return false; - } - } - - protected boolean containsPositiveLong(String property) - { - try - { - long value = _config.getLong(property); - return value > 0; - } - catch (NoSuchElementException e) - { - return false; - } - - } - - protected boolean containsInt(String property) - { - try - { - _config.getInt(property); - return true; - } - catch (NoSuchElementException e) - { - return false; - } - } - - protected boolean containsBoolean(String property) - { - try - { - _config.getBoolean(property); - return true; - } - catch (NoSuchElementException e) - { - return false; - } - } - - public static String escapeTagName(String name) - { - return name.replaceAll("\\.", "\\.\\."); - } - - protected void setConfig(Configuration config) - { - _config = config; - } - - protected Map<String,String> getMap(String name) - { - List elements = getListValue(name,Collections.emptyList()); - - Map<String,String> map = new LinkedHashMap(); - for(Object item : elements) - { - String[] keyValue = String.valueOf(item).split("=",2); - map.put(keyValue[0].trim(), keyValue.length > 1 ? keyValue[1].trim() : null); - } - return map; - } -} - - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AccessControlProviderRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AccessControlProviderRecoverer.java deleted file mode 100644 index df80b9fe5f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AccessControlProviderRecoverer.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import java.util.Map; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.model.AccessControlProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.adapter.AccessControlProviderFactory; - -public class AccessControlProviderRecoverer implements ConfiguredObjectRecoverer<AccessControlProvider> -{ - private final AccessControlProviderFactory _accessControlProviderFactory; - - public AccessControlProviderRecoverer(AccessControlProviderFactory authenticationProviderFactory) - { - _accessControlProviderFactory = authenticationProviderFactory; - } - - @Override - public AccessControlProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) - { - Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); - Map<String, Object> attributes = configurationEntry.getAttributes(); - AccessControlProvider authenticationProvider = _accessControlProviderFactory.recover( - configurationEntry.getId(), - broker, - attributes); - - return authenticationProvider; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java deleted file mode 100644 index 8eec88d556..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import java.util.Collection; -import java.util.Map; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; - -public class AuthenticationProviderRecoverer implements ConfiguredObjectRecoverer<AuthenticationProvider> -{ - private final AuthenticationProviderFactory _authenticationProviderFactory; - private final StoreConfigurationChangeListener _storeChangeListener; - - public AuthenticationProviderRecoverer(AuthenticationProviderFactory authenticationProviderFactory, StoreConfigurationChangeListener storeChangeListener) - { - _authenticationProviderFactory = authenticationProviderFactory; - _storeChangeListener = storeChangeListener; - } - - @Override - public AuthenticationProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) - { - Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); - Map<String, Object> attributes = configurationEntry.getAttributes(); - AuthenticationProvider authenticationProvider = _authenticationProviderFactory.recover(configurationEntry.getId(), attributes, broker); - - Map<String, Collection<ConfigurationEntry>> childEntries = configurationEntry.getChildren(); - - for (String type : childEntries.keySet()) - { - recoverType(recovererProvider, _storeChangeListener, authenticationProvider, childEntries, type); - } - - return authenticationProvider; - } - - private void recoverType(RecovererProvider recovererProvider, - StoreConfigurationChangeListener storeChangeListener, - AuthenticationProvider authenticationProvider, - Map<String, Collection<ConfigurationEntry>> childEntries, - String type) - { - ConfiguredObjectRecoverer<?> recoverer = recovererProvider.getRecoverer(type); - if (recoverer == null) - { - throw new IllegalConfigurationException("Cannot recover entry for the type '" + type + "' from broker"); - } - Collection<ConfigurationEntry> entries = childEntries.get(type); - for (ConfigurationEntry childEntry : entries) - { - ConfiguredObject object = recoverer.create(recovererProvider, childEntry, authenticationProvider); - if (object == null) - { - throw new IllegalConfigurationException("Cannot create configured object for the entry " + childEntry); - } - if (object instanceof PreferencesProvider) - { - authenticationProvider.setPreferencesProvider((PreferencesProvider)object); - } - else - { - throw new IllegalConfigurationException("Cannot associate " + object + " with authentication provider " + authenticationProvider); - } - object.addChangeListener(storeChangeListener); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java deleted file mode 100644 index 4923565e26..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - -import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.logging.LogRecorder; -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.Model; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.model.adapter.AccessControlProviderFactory; -import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; -import org.apache.qpid.server.model.adapter.BrokerAdapter; -import org.apache.qpid.server.model.adapter.GroupProviderFactory; -import org.apache.qpid.server.model.adapter.PortFactory; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.util.MapValueConverter; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; - -public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker> -{ - private static final Pattern MODEL_VERSION_PATTERN = Pattern.compile("^\\d+\\.\\d+$"); - - private final StatisticsGatherer _statisticsGatherer; - private final VirtualHostRegistry _virtualHostRegistry; - private final LogRecorder _logRecorder; - private final RootMessageLogger _rootMessageLogger; - private final AuthenticationProviderFactory _authenticationProviderFactory; - private final AccessControlProviderFactory _accessControlProviderFactory; - private final PortFactory _portFactory; - private final TaskExecutor _taskExecutor; - private final BrokerOptions _brokerOptions; - private final GroupProviderFactory _groupProviderFactory; - private final StoreConfigurationChangeListener _storeChangeListener; - private final PreferencesProviderCreator _preferencesProviderCreator; - - public BrokerRecoverer(AuthenticationProviderFactory authenticationProviderFactory, GroupProviderFactory groupProviderFactory, - AccessControlProviderFactory accessControlProviderFactory, PortFactory portFactory, PreferencesProviderCreator preferencesProviderFactory, StatisticsGatherer statisticsGatherer, - VirtualHostRegistry virtualHostRegistry, LogRecorder logRecorder, RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor, - BrokerOptions brokerOptions, StoreConfigurationChangeListener storeChangeListener) - { - _groupProviderFactory = groupProviderFactory; - _portFactory = portFactory; - _authenticationProviderFactory = authenticationProviderFactory; - _accessControlProviderFactory = accessControlProviderFactory; - _statisticsGatherer = statisticsGatherer; - _virtualHostRegistry = virtualHostRegistry; - _logRecorder = logRecorder; - _rootMessageLogger = rootMessageLogger; - _taskExecutor = taskExecutor; - _brokerOptions = brokerOptions; - _storeChangeListener = storeChangeListener; - _preferencesProviderCreator = preferencesProviderFactory; - } - - @Override - public Broker create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) - { - //Map<String, Object> attributes = entry.getAttributes(); - Map<String, Object> attributesCopy = validateAttributes(entry); - - attributesCopy.put(Broker.MODEL_VERSION, Model.MODEL_VERSION); - - BrokerAdapter broker = new BrokerAdapter(entry.getId(), attributesCopy, _statisticsGatherer, _virtualHostRegistry, - _logRecorder, _rootMessageLogger, _authenticationProviderFactory,_groupProviderFactory, _accessControlProviderFactory, - _portFactory , _preferencesProviderCreator, _taskExecutor, entry.getStore(), _brokerOptions); - - broker.addChangeListener(_storeChangeListener); - - //Recover the SSL keystores / truststores first, then others that depend on them - Map<String, Collection<ConfigurationEntry>> childEntries = new HashMap<String, Collection<ConfigurationEntry>>(entry.getChildren()); - Map<String, Collection<ConfigurationEntry>> priorityChildEntries = new HashMap<String, Collection<ConfigurationEntry>>(childEntries); - List<String> types = new ArrayList<String>(childEntries.keySet()); - - for(String type : types) - { - if(KeyStore.class.getSimpleName().equals(type) || TrustStore.class.getSimpleName().equals(type) - || AuthenticationProvider.class.getSimpleName().equals(type)) - { - childEntries.remove(type); - } - else - { - priorityChildEntries.remove(type); - } - } - - for (String type : priorityChildEntries.keySet()) - { - recoverType(recovererProvider, _storeChangeListener, broker, priorityChildEntries, type); - } - for (String type : childEntries.keySet()) - { - recoverType(recovererProvider, _storeChangeListener, broker, childEntries, type); - } - - return broker; - } - - private Map<String, Object> validateAttributes(ConfigurationEntry entry) - { - Map<String, Object> attributes = entry.getAttributes(); - - String modelVersion = null; - if (attributes.containsKey(Broker.MODEL_VERSION)) - { - modelVersion = MapValueConverter.getStringAttribute(Broker.MODEL_VERSION, attributes, null); - } - - if (modelVersion == null) - { - throw new IllegalConfigurationException("Broker " + Broker.MODEL_VERSION + " must be specified"); - } - - if (!MODEL_VERSION_PATTERN.matcher(modelVersion).matches()) - { - throw new IllegalConfigurationException("Broker " + Broker.MODEL_VERSION + " is specified in incorrect format: " - + modelVersion); - } - - int versionSeparatorPosition = modelVersion.indexOf("."); - String majorVersionPart = modelVersion.substring(0, versionSeparatorPosition); - int majorModelVersion = Integer.parseInt(majorVersionPart); - int minorModelVersion = Integer.parseInt(modelVersion.substring(versionSeparatorPosition + 1)); - - if (majorModelVersion != Model.MODEL_MAJOR_VERSION || minorModelVersion > Model.MODEL_MINOR_VERSION) - { - throw new IllegalConfigurationException("The model version '" + modelVersion - + "' in configuration is incompatible with the broker model version '" + Model.MODEL_VERSION + "'"); - } - - if(!Model.MODEL_VERSION.equals(modelVersion)) - { - String oldVersion; - do - { - oldVersion = modelVersion; - StoreUpgrader.upgrade(entry.getStore()); - entry = entry.getStore().getRootEntry(); - attributes = entry.getAttributes(); - modelVersion = MapValueConverter.getStringAttribute(Broker.MODEL_VERSION, attributes, null); - } - while(!(modelVersion.equals(oldVersion) || modelVersion.equals(Model.MODEL_VERSION))); - } - - return new HashMap<String, Object>(attributes); - } - - private void recoverType(RecovererProvider recovererProvider, - StoreConfigurationChangeListener storeChangeListener, - BrokerAdapter broker, - Map<String, Collection<ConfigurationEntry>> childEntries, - String type) - { - ConfiguredObjectRecoverer<?> recoverer = recovererProvider.getRecoverer(type); - if (recoverer == null) - { - throw new IllegalConfigurationException("Cannot recover entry for the type '" + type + "' from broker"); - } - Collection<ConfigurationEntry> entries = childEntries.get(type); - for (ConfigurationEntry childEntry : entries) - { - ConfiguredObject object = recoverer.create(recovererProvider, childEntry, broker); - if (object == null) - { - throw new IllegalConfigurationException("Cannot create configured object for the entry " + childEntry); - } - broker.recoverChild(object); - object.addChangeListener(storeChangeListener); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java deleted file mode 100644 index 67268c9854..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.logging.LogRecorder; -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.model.AccessControlProvider; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.GroupProvider; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.Plugin; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.model.adapter.AccessControlProviderFactory; -import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; -import org.apache.qpid.server.model.adapter.GroupProviderFactory; -import org.apache.qpid.server.model.adapter.PortFactory; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; -import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.plugin.AccessControlFactory; -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; -import org.apache.qpid.server.plugin.GroupManagerFactory; -import org.apache.qpid.server.plugin.PluginFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; - -public class DefaultRecovererProvider implements RecovererProvider -{ - - private final StatisticsGatherer _brokerStatisticsGatherer; - private final VirtualHostRegistry _virtualHostRegistry; - private final LogRecorder _logRecorder; - private final RootMessageLogger _rootMessageLogger; - private final AuthenticationProviderFactory _authenticationProviderFactory; - private final AccessControlProviderFactory _accessControlProviderFactory; - private final PortFactory _portFactory; - private final GroupProviderFactory _groupProviderFactory; - private final QpidServiceLoader<PluginFactory> _pluginFactoryServiceLoader; - private final TaskExecutor _taskExecutor; - private final BrokerOptions _brokerOptions; - private final StoreConfigurationChangeListener _storeChangeListener; - private final PreferencesProviderCreator _preferencesProviderCreator; - - public DefaultRecovererProvider(StatisticsGatherer brokerStatisticsGatherer, VirtualHostRegistry virtualHostRegistry, - LogRecorder logRecorder, RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor, BrokerOptions brokerOptions, StoreConfigurationChangeListener storeChangeListener) - { - _preferencesProviderCreator = new PreferencesProviderCreator(); - _authenticationProviderFactory = new AuthenticationProviderFactory(new QpidServiceLoader<AuthenticationManagerFactory>(), _preferencesProviderCreator); - _accessControlProviderFactory = new AccessControlProviderFactory(new QpidServiceLoader<AccessControlFactory>()); - _groupProviderFactory = new GroupProviderFactory(new QpidServiceLoader<GroupManagerFactory>()); - _portFactory = new PortFactory(); - _brokerStatisticsGatherer = brokerStatisticsGatherer; - _virtualHostRegistry = virtualHostRegistry; - _logRecorder = logRecorder; - _rootMessageLogger = rootMessageLogger; - _pluginFactoryServiceLoader = new QpidServiceLoader<PluginFactory>(); - _taskExecutor = taskExecutor; - _brokerOptions = brokerOptions; - _storeChangeListener = storeChangeListener; - } - - @Override - public ConfiguredObjectRecoverer<?> getRecoverer(String type) - { - if (Broker.class.getSimpleName().equals(type)) - { - return new BrokerRecoverer(_authenticationProviderFactory, _groupProviderFactory, _accessControlProviderFactory, _portFactory, _preferencesProviderCreator, - _brokerStatisticsGatherer, _virtualHostRegistry, _logRecorder, _rootMessageLogger, _taskExecutor, _brokerOptions, _storeChangeListener); - } - else if(VirtualHost.class.getSimpleName().equals(type)) - { - return new VirtualHostRecoverer(_brokerStatisticsGatherer); - } - else if(AccessControlProvider.class.getSimpleName().equals(type)) - { - return new AccessControlProviderRecoverer(_accessControlProviderFactory); - } - else if(AuthenticationProvider.class.getSimpleName().equals(type)) - { - return new AuthenticationProviderRecoverer(_authenticationProviderFactory, _storeChangeListener); - } - else if(Port.class.getSimpleName().equals(type)) - { - return new PortRecoverer(_portFactory); - } - else if(GroupProvider.class.getSimpleName().equals(type)) - { - return new GroupProviderRecoverer(_groupProviderFactory); - } - else if(KeyStore.class.getSimpleName().equals(type)) - { - return new KeyStoreRecoverer(); - } - else if(TrustStore.class.getSimpleName().equals(type)) - { - return new TrustStoreRecoverer(); - } - else if(PreferencesProvider.class.getSimpleName().equals(type)) - { - return new PreferencesProviderRecoverer(_preferencesProviderCreator); - } - else if(Plugin.class.getSimpleName().equals(type)) - { - return new PluginRecoverer(_pluginFactoryServiceLoader); - } - - return null; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java deleted file mode 100644 index 00f23b3c1c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import java.util.Map; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.GroupProvider; -import org.apache.qpid.server.model.adapter.GroupProviderFactory; - -public class GroupProviderRecoverer implements ConfiguredObjectRecoverer<GroupProvider> -{ - private GroupProviderFactory _groupProviderFactory; - - public GroupProviderRecoverer(GroupProviderFactory groupProviderFactory) - { - super(); - _groupProviderFactory = groupProviderFactory; - } - - @Override - public GroupProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) - { - Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); - Map<String, Object> attributes = configurationEntry.getAttributes(); - - GroupProvider groupProvider = _groupProviderFactory.recover(configurationEntry.getId(), broker, attributes); - - return groupProvider; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java deleted file mode 100644 index 8efedd37b5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.adapter.KeyStoreAdapter; - -public class KeyStoreRecoverer implements ConfiguredObjectRecoverer<KeyStore> -{ - @Override - public KeyStore create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) - { - Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); - return new KeyStoreAdapter(entry.getId(), broker, entry.getAttributes()); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java deleted file mode 100644 index ddc4482953..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.plugin.PluginFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class PluginRecoverer implements ConfiguredObjectRecoverer<ConfiguredObject> -{ - private QpidServiceLoader<PluginFactory> _serviceLoader; - - public PluginRecoverer(QpidServiceLoader<PluginFactory> serviceLoader) - { - _serviceLoader = serviceLoader; - } - - @Override - public ConfiguredObject create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) - { - Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); - Map<String, Object> attributes = configurationEntry.getAttributes(); - Iterable<PluginFactory> factories = _serviceLoader.instancesOf(PluginFactory.class); - for (PluginFactory pluginFactory : factories) - { - UUID configurationId = configurationEntry.getId(); - ConfiguredObject pluginObject = pluginFactory.createInstance(configurationId, attributes, broker); - if (pluginObject != null) - { - UUID pluginId = pluginObject.getId(); - if (!configurationId.equals(pluginId)) - { - throw new IllegalStateException("Plugin object id '" + pluginId + "' does not equal expected id " + configurationId); - } - return pluginObject; - } - } - throw new IllegalConfigurationException("Cannot create a plugin object for " + attributes + " with factories " + factories); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java deleted file mode 100644 index 147e835a8d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.adapter.BrokerAdapter; -import org.apache.qpid.server.model.adapter.PortFactory; - -public class PortRecoverer implements ConfiguredObjectRecoverer<Port> -{ - /** - * delegates to a {@link PortFactory} so that the logic can be shared by - * {@link BrokerAdapter} - */ - private final PortFactory _portFactory; - - public PortRecoverer(PortFactory portFactory) - { - _portFactory = portFactory; - } - - @Override - public Port create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) - { - Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); - return _portFactory.createPort(configurationEntry.getId(), broker, configurationEntry.getAttributes()); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecoverer.java deleted file mode 100644 index a455a61fee..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecoverer.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apache.qpid.server.configuration.startup; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; - -public class PreferencesProviderRecoverer implements ConfiguredObjectRecoverer<PreferencesProvider> -{ - - private PreferencesProviderCreator _preferencesProviderCreator; - - public PreferencesProviderRecoverer(PreferencesProviderCreator preferencesProviderCreator) - { - _preferencesProviderCreator = preferencesProviderCreator; - } - - @Override - public PreferencesProvider create(RecovererProvider recovererProvider, ConfigurationEntry entry, - ConfiguredObject... parents) - { - if (parents == null || parents.length == 0) - { - throw new IllegalArgumentException("AuthenticationProvider parent is not passed!"); - } - if (parents.length != 1) - { - throw new IllegalArgumentException("Only one parent is expected!"); - } - if (!(parents[0] instanceof AuthenticationProvider)) - { - throw new IllegalArgumentException("Parent is not a AuthenticationProvider"); - } - AuthenticationProvider authenticationProvider = (AuthenticationProvider)parents[0]; - return _preferencesProviderCreator.recover(entry.getId(), entry.getAttributes(), authenticationProvider); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java deleted file mode 100644 index b60c9c289f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; - -public class RecovererHelper -{ - public static Broker verifyOnlyBrokerIsParent(ConfiguredObject... parents) - { - if (parents == null || parents.length == 0) - { - throw new IllegalArgumentException("Broker parent is not passed!"); - } - if (parents.length != 1) - { - throw new IllegalArgumentException("Only one parent is expected!"); - } - if (!(parents[0] instanceof Broker)) - { - throw new IllegalArgumentException("Parent is not a broker"); - } - return (Broker)parents[0]; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/StoreUpgrader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/StoreUpgrader.java deleted file mode 100644 index 0789664dd8..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/StoreUpgrader.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.apache.qpid.server.configuration.startup;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.model.Broker; - -public abstract class StoreUpgrader -{ - - private static Map<String, StoreUpgrader> _upgraders = new HashMap<String, StoreUpgrader>(); - - // Note: don't use externally defined constants in upgraders in case they change, the values here MUST stay the same - // no matter what changes are made to the code in the future - - private final static StoreUpgrader UPGRADE_1_0 = new StoreUpgrader("1.0") - { - @Override - protected void doUpgrade(ConfigurationEntryStore store) - { - ConfigurationEntry root = store.getRootEntry(); - Map<String, Collection<ConfigurationEntry>> children = root.getChildren(); - Collection<ConfigurationEntry> vhosts = children.get("VirtualHost"); - Collection<ConfigurationEntry> changed = new HashSet<ConfigurationEntry>(); - for(ConfigurationEntry vhost : vhosts) - { - Map<String, Object> attributes = vhost.getAttributes(); - if(attributes.containsKey("storeType")) - { - attributes = new HashMap<String, Object>(attributes); - attributes.put("type", "STANDARD"); - - changed.add(new ConfigurationEntry(vhost.getId(),vhost.getType(),attributes,vhost.getChildrenIds(),store)); - - } - - } - Map<String, Object> attributes = new HashMap<String, Object>(root.getAttributes()); - attributes.put(Broker.MODEL_VERSION, "1.1"); - changed.add(new ConfigurationEntry(root.getId(),root.getType(),attributes,root.getChildrenIds(),store)); - - store.save(changed.toArray(new ConfigurationEntry[changed.size()])); - - } - }; - - private StoreUpgrader(String version) - { - _upgraders.put(version, this); - } - - public static void upgrade(ConfigurationEntryStore store) - { - StoreUpgrader upgrader = _upgraders.get(store.getRootEntry().getAttributes().get(Broker.MODEL_VERSION).toString()); - if(upgrader != null) - { - upgrader.doUpgrade(store); - } - } - - protected abstract void doUpgrade(ConfigurationEntryStore store); - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java deleted file mode 100644 index 7e9428a4d6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.model.adapter.TrustStoreAdapter; - -public class TrustStoreRecoverer implements ConfiguredObjectRecoverer<TrustStore> -{ - @Override - public TrustStore create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) - { - Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); - return new TrustStoreAdapter(entry.getId(), broker, entry.getAttributes()); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java deleted file mode 100644 index 4f863adfb5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.startup; - - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.model.adapter.VirtualHostAdapter; -import org.apache.qpid.server.stats.StatisticsGatherer; - -public class VirtualHostRecoverer implements ConfiguredObjectRecoverer<VirtualHost> -{ - private StatisticsGatherer _brokerStatisticsGatherer; - - public VirtualHostRecoverer(StatisticsGatherer brokerStatisticsGatherer) - { - super(); - _brokerStatisticsGatherer = brokerStatisticsGatherer; - } - - @Override - public VirtualHost create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) - { - Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); - - return new VirtualHostAdapter(entry.getId(), entry.getAttributes(), broker, _brokerStatisticsGatherer, broker.getTaskExecutor()); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreUtil.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreUtil.java deleted file mode 100644 index 6d895892b3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreUtil.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.store; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.util.FileUtils; - -public class ConfigurationEntryStoreUtil -{ - public void copyInitialConfigFile(String initialConfigLocation, File destinationFile) - { - URL initialStoreURL = toURL(initialConfigLocation); - InputStream in = null; - try - { - in = initialStoreURL.openStream(); - FileUtils.copy(in, destinationFile); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot create file " + destinationFile + " by copying initial config from " + initialConfigLocation , e); - } - finally - { - if (in != null) - { - try - { - in.close(); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot close initial config input stream: " + initialConfigLocation , e); - } - } - } - } - - public URL toURL(String location) - { - URL url = null; - try - { - url = new URL(location); - } - catch (MalformedURLException e) - { - File locationFile = new File(location); - url = fileToURL(locationFile); - } - return url; - } - - protected URL fileToURL(File storeFile) - { - URL storeURL = null; - try - { - storeURL = storeFile.toURI().toURL(); - } - catch (MalformedURLException e) - { - throw new IllegalConfigurationException("Cannot create URL for file " + storeFile, e); - } - return storeURL; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java deleted file mode 100644 index df82822a86..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.store; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.IllegalConfigurationException; - -public class JsonConfigurationEntryStore extends MemoryConfigurationEntryStore -{ - public static final String STORE_TYPE = "json"; - - private File _storeFile; - - public JsonConfigurationEntryStore(String storeLocation, ConfigurationEntryStore initialStore, boolean overwrite, Map<String, String> configProperties) - { - super(configProperties); - _storeFile = new File(storeLocation); - - if(_storeFile.isDirectory()) - { - throw new IllegalConfigurationException("A directory exists at the location for the broker configuration store file: " + storeLocation); - } - - if(overwrite && _storeFile.exists()) - { - if(!_storeFile.delete()) - { - throw new RuntimeException("Unable to overwrite existing configuration store file as requested: " + storeLocation); - } - } - - if ((!_storeFile.exists() || _storeFile.length() == 0)) - { - initialiseStore(_storeFile, initialStore); - } - load(getConfigurationEntryStoreUtil().fileToURL(_storeFile)); - if(isGeneratedObjectIdDuringLoad()) - { - saveAsTree(_storeFile); - } - } - - @Override - public synchronized UUID[] remove(UUID... entryIds) - { - UUID[] removedIds = super.remove(entryIds); - if (removedIds.length > 0) - { - saveAsTree(_storeFile); - } - return removedIds; - } - - @Override - public synchronized void save(ConfigurationEntry... entries) - { - if (replaceEntries(entries)) - { - saveAsTree(_storeFile); - } - } - - @Override - public String getStoreLocation() - { - return _storeFile.getAbsolutePath(); - } - - @Override - public String getType() - { - return STORE_TYPE; - } - - @Override - public String toString() - { - return "JsonConfigurationEntryStore [_storeFile=" + _storeFile + ", _rootId=" + getRootEntry().getId() + "]"; - } - - private void initialiseStore(File storeFile, ConfigurationEntryStore initialStore) - { - createFileIfNotExist(storeFile); - if (initialStore == null) - { - throw new IllegalConfigurationException("Cannot create new store without an initial store"); - } - else - { - if (initialStore instanceof MemoryConfigurationEntryStore && initialStore.getStoreLocation() != null) - { - getConfigurationEntryStoreUtil().copyInitialConfigFile(initialStore.getStoreLocation(), storeFile); - } - else - { - ConfigurationEntry rootEntry = initialStore.getRootEntry(); - Map<UUID, ConfigurationEntry> entries = new HashMap<UUID, ConfigurationEntry>(); - copyEntry(rootEntry.getId(), initialStore, entries); - saveAsTree(rootEntry.getId(), entries, getObjectMapper(), storeFile, getVersion()); - } - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java deleted file mode 100644 index 639f3cd5c4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java +++ /dev/null @@ -1,353 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.store; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Protocol; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.util.MapValueConverter; - -public class ManagementModeStoreHandler implements ConfigurationEntryStore -{ - private static final Logger LOGGER = Logger.getLogger(ManagementModeStoreHandler.class); - - private static final String MANAGEMENT_MODE_PORT_PREFIX = "MANAGEMENT-MODE-PORT-"; - private static final String PORT_TYPE = Port.class.getSimpleName(); - private static final String VIRTUAL_HOST_TYPE = VirtualHost.class.getSimpleName(); - private static final String ATTRIBUTE_STATE = VirtualHost.STATE; - private static final Object MANAGEMENT_MODE_AUTH_PROVIDER = "mm-auth"; - - - private final ConfigurationEntryStore _store; - private final Map<UUID, ConfigurationEntry> _cliEntries; - private final Map<UUID, Object> _quiescedEntries; - private final UUID _rootId; - - public ManagementModeStoreHandler(ConfigurationEntryStore store, BrokerOptions options) - { - ConfigurationEntry storeRoot = store.getRootEntry(); - _store = store; - _rootId = storeRoot.getId(); - _cliEntries = createPortsFromCommadLineOptions(options); - _quiescedEntries = quiesceEntries(storeRoot, options); - } - - @Override - public ConfigurationEntry getRootEntry() - { - return getEntry(_rootId); - } - - @Override - public ConfigurationEntry getEntry(UUID id) - { - synchronized (_store) - { - if (_cliEntries.containsKey(id)) - { - return _cliEntries.get(id); - } - - ConfigurationEntry entry = _store.getEntry(id); - if (_quiescedEntries.containsKey(id)) - { - entry = createEntryWithState(entry, State.QUIESCED); - } - else if (id == _rootId) - { - entry = createRootWithCLIEntries(entry); - } - return entry; - } - } - - @Override - public void save(ConfigurationEntry... entries) - { - synchronized (_store) - { - ConfigurationEntry[] entriesToSave = new ConfigurationEntry[entries.length]; - - for (int i = 0; i < entries.length; i++) - { - ConfigurationEntry entry = entries[i]; - UUID id = entry.getId(); - if (_cliEntries.containsKey(id)) - { - throw new IllegalConfigurationException("Cannot save configuration provided as command line argument:" - + entry); - } - else if (_quiescedEntries.containsKey(id)) - { - // save entry with the original state - entry = createEntryWithState(entry, _quiescedEntries.get(ATTRIBUTE_STATE)); - } - else if (_rootId.equals(id)) - { - // save root without command line entries - Set<UUID> childrenIds = new HashSet<UUID>(entry.getChildrenIds()); - if (!_cliEntries.isEmpty()) - { - childrenIds.removeAll(_cliEntries.entrySet()); - } - HashMap<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); - entry = new ConfigurationEntry(entry.getId(), entry.getType(), attributes, childrenIds, this); - } - entriesToSave[i] = entry; - } - - _store.save(entriesToSave); - } - } - - @Override - public UUID[] remove(UUID... entryIds) - { - synchronized (_store) - { - for (UUID id : entryIds) - { - if (_cliEntries.containsKey(id)) - { - throw new IllegalConfigurationException("Cannot change configuration for command line entry:" - + _cliEntries.get(id)); - } - } - UUID[] result = _store.remove(entryIds); - for (UUID id : entryIds) - { - if (_quiescedEntries.containsKey(id)) - { - _quiescedEntries.remove(id); - } - } - return result; - } - } - - @Override - public void copyTo(String copyLocation) - { - synchronized (_store) - { - _store.copyTo(copyLocation); - } - } - - @Override - public String getStoreLocation() - { - return _store.getStoreLocation(); - } - - @Override - public int getVersion() - { - return _store.getVersion(); - } - - @Override - public String getType() - { - return _store.getType(); - } - - private Map<UUID, ConfigurationEntry> createPortsFromCommadLineOptions(BrokerOptions options) - { - int managementModeRmiPortOverride = options.getManagementModeRmiPortOverride(); - if (managementModeRmiPortOverride < 0) - { - throw new IllegalConfigurationException("Invalid rmi port is specified: " + managementModeRmiPortOverride); - } - int managementModeJmxPortOverride = options.getManagementModeJmxPortOverride(); - if (managementModeJmxPortOverride < 0) - { - throw new IllegalConfigurationException("Invalid jmx port is specified: " + managementModeJmxPortOverride); - } - int managementModeHttpPortOverride = options.getManagementModeHttpPortOverride(); - if (managementModeHttpPortOverride < 0) - { - throw new IllegalConfigurationException("Invalid http port is specified: " + managementModeHttpPortOverride); - } - Map<UUID, ConfigurationEntry> cliEntries = new HashMap<UUID, ConfigurationEntry>(); - if (managementModeRmiPortOverride != 0) - { - ConfigurationEntry entry = createCLIPortEntry(managementModeRmiPortOverride, Protocol.RMI); - cliEntries.put(entry.getId(), entry); - if (managementModeJmxPortOverride == 0) - { - ConfigurationEntry connectorEntry = createCLIPortEntry(managementModeRmiPortOverride + 100, Protocol.JMX_RMI); - cliEntries.put(connectorEntry.getId(), connectorEntry); - } - } - if (managementModeJmxPortOverride != 0) - { - ConfigurationEntry entry = createCLIPortEntry(managementModeJmxPortOverride, Protocol.JMX_RMI); - cliEntries.put(entry.getId(), entry); - } - if (managementModeHttpPortOverride != 0) - { - ConfigurationEntry entry = createCLIPortEntry(managementModeHttpPortOverride, Protocol.HTTP); - cliEntries.put(entry.getId(), entry); - } - return cliEntries; - } - - private ConfigurationEntry createCLIPortEntry(int port, Protocol protocol) - { - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(Port.PORT, port); - attributes.put(Port.PROTOCOLS, Collections.singleton(protocol)); - attributes.put(Port.NAME, MANAGEMENT_MODE_PORT_PREFIX + protocol.name()); - if (protocol != Protocol.RMI) - { - attributes.put(Port.AUTHENTICATION_PROVIDER, MANAGEMENT_MODE_AUTH_PROVIDER); - } - ConfigurationEntry portEntry = new ConfigurationEntry(UUID.randomUUID(), PORT_TYPE, attributes, - Collections.<UUID> emptySet(), this); - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("Add management mode port configuration " + portEntry + " for port " + port + " and protocol " - + protocol); - } - return portEntry; - } - - private ConfigurationEntry createRootWithCLIEntries(ConfigurationEntry storeRoot) - { - Set<UUID> childrenIds = new HashSet<UUID>(storeRoot.getChildrenIds()); - if (!_cliEntries.isEmpty()) - { - childrenIds.addAll(_cliEntries.keySet()); - } - ConfigurationEntry root = new ConfigurationEntry(storeRoot.getId(), storeRoot.getType(), new HashMap<String, Object>( - storeRoot.getAttributes()), childrenIds, this); - return root; - } - - private Map<UUID, Object> quiesceEntries(ConfigurationEntry storeRoot, BrokerOptions options) - { - Map<UUID, Object> quiescedEntries = new HashMap<UUID, Object>(); - Set<UUID> childrenIds; - int managementModeRmiPortOverride = options.getManagementModeRmiPortOverride(); - int managementModeJmxPortOverride = options.getManagementModeJmxPortOverride(); - int managementModeHttpPortOverride = options.getManagementModeHttpPortOverride(); - childrenIds = storeRoot.getChildrenIds(); - for (UUID id : childrenIds) - { - ConfigurationEntry entry = _store.getEntry(id); - String entryType = entry.getType(); - Map<String, Object> attributes = entry.getAttributes(); - boolean quiesce = false; - if (VIRTUAL_HOST_TYPE.equals(entryType) && options.isManagementModeQuiesceVirtualHosts()) - { - quiesce = true; - } - else if (PORT_TYPE.equals(entryType)) - { - if (attributes == null) - { - throw new IllegalConfigurationException("Port attributes are not set in " + entry); - } - Set<Protocol> protocols = getPortProtocolsAttribute(attributes); - if (protocols == null) - { - quiesce = true; - } - else - { - for (Protocol protocol : protocols) - { - switch (protocol) - { - case JMX_RMI: - quiesce = managementModeJmxPortOverride > 0 || managementModeRmiPortOverride > 0; - break; - case RMI: - quiesce = managementModeRmiPortOverride > 0; - break; - case HTTP: - quiesce = managementModeHttpPortOverride > 0; - break; - default: - quiesce = true; - } - } - } - } - if (quiesce) - { - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("Management mode quiescing entry " + entry); - } - - // save original state - quiescedEntries.put(entry.getId(), attributes.get(ATTRIBUTE_STATE)); - } - } - return quiescedEntries; - } - - private Set<Protocol> getPortProtocolsAttribute(Map<String, Object> attributes) - { - Object object = attributes.get(Port.PROTOCOLS); - if (object == null) - { - return null; - } - return MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, attributes, Protocol.class); - } - - private ConfigurationEntry createEntryWithState(ConfigurationEntry entry, Object state) - { - Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); - if (state == null) - { - attributes.remove(ATTRIBUTE_STATE); - } - else - { - attributes.put(ATTRIBUTE_STATE, state); - } - Set<UUID> originalChildren = entry.getChildrenIds(); - Set<UUID> children = null; - if (originalChildren != null) - { - children = new HashSet<UUID>(originalChildren); - } - return new ConfigurationEntry(entry.getId(), entry.getType(), attributes, children, entry.getStore()); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java deleted file mode 100644 index 92d170fad9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java +++ /dev/null @@ -1,709 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.store; - -import static org.apache.qpid.server.configuration.ConfigurationEntry.ATTRIBUTE_NAME; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.UUID; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Model; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.util.Strings; -import org.apache.qpid.util.Strings.ChainedResolver; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.JsonParser; -import org.codehaus.jackson.JsonProcessingException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; -import org.codehaus.jackson.node.ArrayNode; - -public class MemoryConfigurationEntryStore implements ConfigurationEntryStore -{ - public static final String STORE_TYPE = "memory"; - - private static final String DEFAULT_BROKER_NAME = "Broker"; - private static final String ID = "id"; - private static final String TYPE = "@type"; - - static final int STORE_VERSION = 1; - - private final ObjectMapper _objectMapper; - private final Map<UUID, ConfigurationEntry> _entries; - private final Map<String, Class<? extends ConfiguredObject>> _relationshipClasses; - private final ConfigurationEntryStoreUtil _util = new ConfigurationEntryStoreUtil(); - - private String _storeLocation; - private UUID _rootId; - - private boolean _generatedObjectIdDuringLoad; - - private ChainedResolver _resolver; - - protected MemoryConfigurationEntryStore(Map<String, String> configProperties) - { - _objectMapper = new ObjectMapper(); - _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); - _objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - _entries = new HashMap<UUID, ConfigurationEntry>(); - _relationshipClasses = buildRelationshipClassMap(); - _resolver = new Strings.ChainedResolver(Strings.SYSTEM_RESOLVER, - new Strings.MapResolver(configProperties)); - } - - MemoryConfigurationEntryStore(String json, Map<String, String> configProperties) - { - this(configProperties); - if (json == null || "".equals(json)) - { - createRootEntry(); - } - else - { - loadFromJson(json); - } - } - - public MemoryConfigurationEntryStore(String initialStoreLocation, ConfigurationEntryStore initialStore, Map<String, String> configProperties) - { - this(configProperties); - if (initialStore == null && (initialStoreLocation == null || "".equals(initialStoreLocation) )) - { - throw new IllegalConfigurationException("Cannot instantiate the memory broker store as neither initial store nor initial store location is provided"); - } - - if (initialStore != null) - { - if (initialStore instanceof MemoryConfigurationEntryStore) - { - _storeLocation = initialStore.getStoreLocation(); - } - _rootId = initialStore.getRootEntry().getId(); - copyEntry(_rootId, initialStore, _entries); - } - else - { - _storeLocation = initialStoreLocation; - load(_util.toURL(_storeLocation)); - } - } - - @Override - public synchronized UUID[] remove(UUID... entryIds) - { - List<UUID> removedIds = new ArrayList<UUID>(); - for (UUID uuid : entryIds) - { - if (_rootId.equals(uuid)) - { - throw new IllegalConfigurationException("Cannot remove root entry"); - } - } - for (UUID uuid : entryIds) - { - if (removeInternal(uuid)) - { - // remove references to the entry from parent entries - for (ConfigurationEntry entry : _entries.values()) - { - if (entry.hasChild(uuid)) - { - Set<UUID> children = new HashSet<UUID>(entry.getChildrenIds()); - children.remove(uuid); - ConfigurationEntry referal = new ConfigurationEntry(entry.getId(), entry.getType(), - entry.getAttributes(), children, this); - _entries.put(entry.getId(), referal); - } - } - removedIds.add(uuid); - } - } - - return removedIds.toArray(new UUID[removedIds.size()]); - } - - @Override - public synchronized void save(ConfigurationEntry... entries) - { - replaceEntries(entries); - } - - @Override - public ConfigurationEntry getRootEntry() - { - return getEntry(_rootId); - } - - @Override - public synchronized ConfigurationEntry getEntry(UUID id) - { - return _entries.get(id); - } - - /** - * Copies the store into the given location - * - * @param target location to copy store into - * @throws IllegalConfigurationException if store cannot be copied into given location - */ - public void copyTo(String copyLocation) - { - File file = new File(copyLocation); - if (!file.exists()) - { - createFileIfNotExist(file); - } - saveAsTree(file); - } - - @Override - public String getStoreLocation() - { - return _storeLocation; - } - - @Override - public int getVersion() - { - return STORE_VERSION; - } - - @Override - public String getType() - { - return STORE_TYPE; - } - - @Override - public String toString() - { - return "MemoryConfigurationEntryStore [_rootId=" + _rootId + "]"; - } - - protected boolean replaceEntries(ConfigurationEntry... entries) - { - boolean anySaved = false; - for (ConfigurationEntry entry : entries) - { - ConfigurationEntry oldEntry = _entries.put(entry.getId(), entry); - if (!entry.equals(oldEntry)) - { - anySaved = true; - } - } - return anySaved; - } - - protected ObjectMapper getObjectMapper() - { - return _objectMapper; - } - - protected void saveAsTree(File file) - { - saveAsTree(_rootId, _entries, _objectMapper, file, STORE_VERSION); - } - - protected void saveAsTree(UUID rootId, Map<UUID, ConfigurationEntry> entries, ObjectMapper mapper, File file, int version) - { - Map<String, Object> tree = toTree(rootId, entries); - tree.put(Broker.STORE_VERSION, version); - try - { - mapper.writeValue(file, tree); - } - catch (JsonGenerationException e) - { - throw new IllegalConfigurationException("Cannot generate json!", e); - } - catch (JsonMappingException e) - { - throw new IllegalConfigurationException("Cannot map objects for json serialization!", e); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot save configuration into " + file + "!", e); - } - } - - protected void load(URL url) - { - InputStream is = null; - try - { - is = url.openStream(); - JsonNode node = loadJsonNodes(is, _objectMapper); - - int storeVersion = 0; - JsonNode storeVersionNode = node.get(Broker.STORE_VERSION); - if (storeVersionNode == null || storeVersionNode.isNull()) - { - throw new IllegalConfigurationException("Broker " + Broker.STORE_VERSION + " attribute must be specified"); - } - else - { - storeVersion = storeVersionNode.getIntValue(); - } - - if (storeVersion != STORE_VERSION) - { - throw new IllegalConfigurationException("The data of version " + storeVersion - + " can not be loaded by store of version " + STORE_VERSION); - } - - ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries, null); - _rootId = brokerEntry.getId(); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot load store from: " + url, e); - } - finally - { - if (is != null) - { - if (is != null) - { - try - { - is.close(); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot close input stream for: " + url, e); - } - } - } - } - } - - protected void createFileIfNotExist(File file) - { - File parent = file.getParentFile(); - if (!parent.exists()) - { - if (!parent.mkdirs()) - { - throw new IllegalConfigurationException("Cannot create folders " + parent); - } - } - try - { - file.createNewFile(); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot create file " + file, e); - } - } - - protected void copyEntry(UUID entryId, ConfigurationEntryStore initialStore, Map<UUID,ConfigurationEntry> entries) - { - ConfigurationEntry entry = initialStore.getEntry(entryId); - if (entry != null) - { - if (entries.containsKey(entryId)) - { - throw new IllegalConfigurationException("Duplicate id is found: " + entryId - + "! The following configuration entries have the same id: " + entries.get(entryId) + ", " + entry); - } - - Set<UUID> children = entry.getChildrenIds(); - Set<UUID> childrenCopy = children == null? null : new HashSet<UUID>(children); - ConfigurationEntry copy = new ConfigurationEntry(entryId, entry.getType(), new HashMap<String, Object>(entry.getAttributes()), childrenCopy, this); - entries.put(entryId, copy); - if (children != null) - { - for (UUID uuid : children) - { - copyEntry(uuid, initialStore, entries); - } - } - } - } - - private void loadFromJson(String json) - { - ByteArrayInputStream bais = null; - try - { - byte[] bytes = json.getBytes("UTF-8"); - bais = new ByteArrayInputStream(bytes); - JsonNode node = loadJsonNodes(bais, _objectMapper); - ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries, null); - _rootId = brokerEntry.getId(); - } - catch(Exception e) - { - throw new IllegalConfigurationException("Cannot create store from json:" + json); - } - finally - { - if (bais != null) - { - try - { - bais.close(); - } - catch (IOException e) - { - // ByteArrayInputStream#close() is an empty method - } - } - } - } - - private void createRootEntry() - { - ConfigurationEntry brokerEntry = new ConfigurationEntry(UUIDGenerator.generateRandomUUID(), - Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), this); - _rootId = brokerEntry.getId(); - _entries.put(_rootId, brokerEntry); - } - - private Map<String, Object> toTree(UUID rootId, Map<UUID, ConfigurationEntry> entries) - { - ConfigurationEntry entry = entries.get(rootId); - if (entry == null || !entry.getId().equals(rootId)) - { - throw new IllegalConfigurationException("Cannot find entry with id " + rootId + "!"); - } - Map<String, Object> tree = new TreeMap<String, Object>(); - Map<String, Object> attributes = entry.getAttributes(); - if (attributes != null) - { - tree.putAll(attributes); - } - tree.put(ID, entry.getId()); - Set<UUID> childrenIds = entry.getChildrenIds(); - if (childrenIds != null && !childrenIds.isEmpty()) - { - for (UUID relationship : childrenIds) - { - ConfigurationEntry child = entries.get(relationship); - if (child != null) - { - String relationshipName = child.getType().toLowerCase() + "s"; - - @SuppressWarnings("unchecked") - Collection<Map<String, Object>> children = (Collection<Map<String, Object>>) tree.get(relationshipName); - if (children == null) - { - children = new ArrayList<Map<String, Object>>(); - tree.put(relationshipName, children); - } - Map<String, Object> childAsMap = toTree(relationship, entries); - children.add(childAsMap); - } - } - } - return tree; - } - - private Map<String, Class<? extends ConfiguredObject>> buildRelationshipClassMap() - { - Map<String, Class<? extends ConfiguredObject>> relationships = new HashMap<String, Class<? extends ConfiguredObject>>(); - - Collection<Class<? extends ConfiguredObject>> children = Model.getInstance().getChildTypes(Broker.class); - for (Class<? extends ConfiguredObject> childClass : children) - { - String name = childClass.getSimpleName().toLowerCase(); - String relationshipName = name + (name.endsWith("s") ? "es" : "s"); - relationships.put(relationshipName, childClass); - } - return relationships; - } - - private boolean removeInternal(UUID entryId) - { - ConfigurationEntry oldEntry = _entries.remove(entryId); - if (oldEntry != null) - { - Set<UUID> children = oldEntry.getChildrenIds(); - if (children != null && !children.isEmpty()) - { - for (UUID childId : children) - { - removeInternal(childId); - } - } - return true; - } - return false; - } - - private JsonNode loadJsonNodes(InputStream is, ObjectMapper mapper) - { - JsonNode root = null; - try - { - root = mapper.readTree(is); - } - catch (JsonProcessingException e) - { - throw new IllegalConfigurationException("Cannot parse json", e); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot read json", e); - } - return root; - } - - private ConfigurationEntry toEntry(JsonNode parent, Class<? extends ConfiguredObject> expectedConfiguredObjectClass, Map<UUID, ConfigurationEntry> entries, Class<? extends ConfiguredObject> parentClass) - { - Map<String, Object> attributes = null; - Set<UUID> childrenIds = new TreeSet<UUID>(); - Iterator<String> fieldNames = parent.getFieldNames(); - String type = null; - String idAsString = null; - while (fieldNames.hasNext()) - { - String fieldName = fieldNames.next(); - JsonNode fieldNode = parent.get(fieldName); - if (fieldName.equals(ID)) - { - idAsString = fieldNode.asText(); - } - else if (fieldName.equals(TYPE)) - { - type = fieldNode.asText(); - } - else if (fieldNode.isArray()) - { - // array containing either broker children or attribute values - Iterator<JsonNode> elements = fieldNode.getElements(); - List<Object> fieldValues = null; - while (elements.hasNext()) - { - JsonNode element = elements.next(); - if (element.isObject()) - { - Class<? extends ConfiguredObject> expectedChildConfiguredObjectClass = _relationshipClasses.get(fieldName); - if (expectedChildConfiguredObjectClass == null && expectedConfiguredObjectClass != null) - { - Collection<Class<? extends ConfiguredObject>> childTypes = Model.getInstance().getChildTypes(expectedConfiguredObjectClass); - for (Class<? extends ConfiguredObject> childType : childTypes) - { - String relationship = childType.getSimpleName().toLowerCase(); - relationship += relationship.endsWith("s") ? "es": "s"; - if (fieldName.equals(relationship)) - { - expectedChildConfiguredObjectClass = childType; - break; - } - } - } - // assuming it is a child node - ConfigurationEntry entry = toEntry(element, expectedChildConfiguredObjectClass, entries, expectedConfiguredObjectClass); - childrenIds.add(entry.getId()); - } - else - { - if (fieldValues == null) - { - fieldValues = new ArrayList<Object>(); - } - fieldValues.add(toObject(element)); - } - } - if (fieldValues != null) - { - Object[] array = fieldValues.toArray(new Object[fieldValues.size()]); - if (attributes == null) - { - attributes = new HashMap<String, Object>(); - } - attributes.put(fieldName, array); - } - } - else if (fieldNode.isObject()) - { - // ignore, in-line objects are not supported yet - } - else - { - // primitive attribute - Object value = toObject(fieldNode); - if (attributes == null) - { - attributes = new HashMap<String, Object>(); - } - attributes.put(fieldName, value); - } - } - - if (type == null) - { - if (expectedConfiguredObjectClass == null) - { - throw new IllegalConfigurationException("Type attribute is not provided for configuration entry " + parent); - } - else - { - type = expectedConfiguredObjectClass.getSimpleName(); - } - } - String name = null; - if (attributes != null) - { - name = (String) attributes.get(ATTRIBUTE_NAME); - } - if ((name == null || "".equals(name))) - { - if (expectedConfiguredObjectClass == Broker.class) - { - name = DEFAULT_BROKER_NAME; - } - else - { - throw new IllegalConfigurationException("Name attribute is not provided for configuration entry " + parent); - } - } - UUID id = null; - if (idAsString == null) - { - id = UUIDGenerator.generateRandomUUID(); - - _generatedObjectIdDuringLoad = true; - } - else - { - try - { - id = UUID.fromString(idAsString); - } - catch (Exception e) - { - throw new IllegalConfigurationException( - "ID attribute value does not conform to UUID format for configuration entry " + parent); - } - } - ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, childrenIds, this); - if (entries.containsKey(id)) - { - throw new IllegalConfigurationException("Duplicate id is found: " + id - + "! The following configuration entries have the same id: " + entries.get(id) + ", " + entry); - } - entries.put(id, entry); - return entry; - } - - private Object toObject(JsonNode node) - { - if (node.isValueNode()) - { - if (node.isBoolean()) - { - return node.asBoolean(); - } - else if (node.isDouble()) - { - return node.asDouble(); - } - else if (node.isInt()) - { - return node.asInt(); - } - else if (node.isLong()) - { - return node.asLong(); - } - else if (node.isNull()) - { - return null; - } - else - { - return Strings.expand(node.asText(), _resolver); - } - } - else if (node.isArray()) - { - return toArray(node); - } - else if (node.isObject()) - { - return toMap(node); - } - else - { - throw new IllegalConfigurationException("Unexpected node: " + node); - } - } - - private Map<String, Object> toMap(JsonNode node) - { - Map<String, Object> object = new TreeMap<String, Object>(); - Iterator<String> fieldNames = node.getFieldNames(); - while (fieldNames.hasNext()) - { - String name = fieldNames.next(); - Object value = toObject(node.get(name)); - object.put(name, value); - } - return object; - } - - private Object toArray(JsonNode node) - { - ArrayNode arrayNode = (ArrayNode) node; - Object[] array = new Object[arrayNode.size()]; - Iterator<JsonNode> elements = arrayNode.getElements(); - for (int i = 0; i < array.length; i++) - { - array[i] = toObject(elements.next()); - } - return array; - } - - protected boolean isGeneratedObjectIdDuringLoad() - { - return _generatedObjectIdDuringLoad; - } - - protected ConfigurationEntryStoreUtil getConfigurationEntryStoreUtil() - { - return _util; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java deleted file mode 100644 index 3022898300..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.store; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.TreeSet; -import java.util.UUID; - -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfigurationChangeListener; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Model; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.VirtualHost; - -public class StoreConfigurationChangeListener implements ConfigurationChangeListener -{ - private ConfigurationEntryStore _store; - - public StoreConfigurationChangeListener(ConfigurationEntryStore store) - { - super(); - _store = store; - } - - @Override - public void stateChanged(ConfiguredObject object, State oldState, State newState) - { - if (newState == State.DELETED) - { - _store.remove(object.getId()); - object.removeChangeListener(this); - } - } - - @Override - public void childAdded(ConfiguredObject object, ConfiguredObject child) - { - // exclude VirtualHost children from storing in broker store - if (!(object instanceof VirtualHost)) - { - child.addChangeListener(this); - ConfigurationEntry parentEntry = toConfigurationEntry(object); - ConfigurationEntry childEntry = toConfigurationEntry(child); - _store.save(parentEntry, childEntry); - } - - } - - @Override - public void childRemoved(ConfiguredObject object, ConfiguredObject child) - { - _store.save(toConfigurationEntry(object)); - } - - @Override - public void attributeSet(ConfiguredObject object, String attrinuteName, Object oldAttributeValue, Object newAttributeValue) - { - _store.save(toConfigurationEntry(object)); - } - - private ConfigurationEntry toConfigurationEntry(ConfiguredObject object) - { - Class<? extends ConfiguredObject> objectType = getConfiguredObjectType(object); - Set<UUID> childrenIds = getChildernIds(object, objectType); - ConfigurationEntry entry = new ConfigurationEntry(object.getId(), objectType.getSimpleName(), - object.getActualAttributes(), childrenIds, _store); - return entry; - } - - private Set<UUID> getChildernIds(ConfiguredObject object, Class<? extends ConfiguredObject> objectType) - { - // Virtual Host children's IDs should not be stored in broker store - if (object instanceof VirtualHost) - { - return Collections.emptySet(); - } - Set<UUID> childrenIds = new TreeSet<UUID>(); - Collection<Class<? extends ConfiguredObject>> childClasses = Model.getInstance().getChildTypes(objectType); - if (childClasses != null) - { - for (Class<? extends ConfiguredObject> childClass : childClasses) - { - Collection<? extends ConfiguredObject> children = object.getChildren(childClass); - if (children != null) - { - for (ConfiguredObject childObject : children) - { - childrenIds.add(childObject.getId()); - } - } - } - } - return childrenIds; - } - - private Class<? extends ConfiguredObject> getConfiguredObjectType(ConfiguredObject object) - { - if (object instanceof Broker) - { - return Broker.class; - } - else if (object instanceof VirtualHost) - { - return VirtualHost.class; - } - else if (object instanceof Port) - { - return Port.class; - } - else if (object instanceof AuthenticationProvider) - { - return AuthenticationProvider.class; - } - return getConfiguredObjectTypeFromImplementedInterfaces(object.getClass()); - } - - @SuppressWarnings("unchecked") - private Class<? extends ConfiguredObject> getConfiguredObjectTypeFromImplementedInterfaces(Class<?> objectClass) - { - // get all implemented interfaces extending ConfiguredObject - Set<Class<?>> interfaces = getImplementedInterfacesExtendingSuper(objectClass, ConfiguredObject.class); - - if (interfaces.size() == 0) - { - throw new RuntimeException("Can not identify the configured object type"); - } - - if (interfaces.size() == 1) - { - return (Class<? extends ConfiguredObject>)interfaces.iterator().next(); - } - - Set<Class<?>> superInterfaces = new HashSet<Class<?>>(); - - // find all super interfaces - for (Class<?> interfaceClass : interfaces) - { - for (Class<?> interfaceClass2 : interfaces) - { - if (interfaceClass != interfaceClass2) - { - if (interfaceClass.isAssignableFrom(interfaceClass2)) - { - superInterfaces.add(interfaceClass); - } - } - } - } - - // remove super interfaces - for (Class<?> superInterface : superInterfaces) - { - interfaces.remove(superInterface); - } - - if (interfaces.size() == 1) - { - return (Class<? extends ConfiguredObject>)interfaces.iterator().next(); - } - else - { - throw new RuntimeException("Can not identify the configured object type as an it implements" - + " more than one configured object interfaces: " + interfaces); - } - - } - - private Set<Class<?>> getImplementedInterfacesExtendingSuper(Class<?> classInstance, Class<?> superInterface) - { - Set<Class<?>> interfaces = new HashSet<Class<?>>(); - Class<?>[] classInterfaces = classInstance.getInterfaces(); - for (Class<?> interfaceClass : classInterfaces) - { - if (interfaceClass!= superInterface && superInterface.isAssignableFrom(interfaceClass)) - { - interfaces.add(interfaceClass); - } - } - Class<?> superClass = classInstance.getSuperclass(); - if (superClass != null) - { - Set<Class<?>> superClassInterfaces = getImplementedInterfacesExtendingSuper(superClass, superInterface); - interfaces.addAll(superClassInterfaces); - } - return interfaces; - } - - @Override - public String toString() - { - return "StoreConfigurationChangeListener [store=" + _store + "]"; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java deleted file mode 100644 index de007e68d7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.store.factory; - -import java.util.Map; - -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore; -import org.apache.qpid.server.plugin.ConfigurationStoreFactory; - -public class JsonConfigurationStoreFactory implements ConfigurationStoreFactory -{ - @Override - public ConfigurationEntryStore createStore(String storeLocation, ConfigurationEntryStore initialStore, boolean overwrite, Map<String, String> configProperties) - { - return new JsonConfigurationEntryStore(storeLocation, initialStore, overwrite, configProperties); - } - - @Override - public String getType() - { - return JsonConfigurationEntryStore.STORE_TYPE; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/MemoryConfigurationStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/MemoryConfigurationStoreFactory.java deleted file mode 100644 index f7a9157144..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/MemoryConfigurationStoreFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.store.factory; - -import java.util.Map; - -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.store.MemoryConfigurationEntryStore; -import org.apache.qpid.server.plugin.ConfigurationStoreFactory; - -public class MemoryConfigurationStoreFactory implements ConfigurationStoreFactory -{ - @Override - public ConfigurationEntryStore createStore(String storeLocation, ConfigurationEntryStore initialStore, boolean overwrite, Map<String, String> configProperties) - { - return new MemoryConfigurationEntryStore(null, initialStore, configProperties); - } - - @Override - public String getType() - { - return MemoryConfigurationEntryStore.STORE_TYPE; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeAttributesTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeAttributesTask.java deleted file mode 100644 index 4ba4057fee..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeAttributesTask.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.updater; - -import java.util.Map; -import java.util.concurrent.Callable; - -import org.apache.qpid.server.model.ConfiguredObject; - -public class ChangeAttributesTask implements Callable<Void> -{ - private final Map<String, Object> _attributes; - private final ConfiguredObject _object; - - public ChangeAttributesTask(ConfiguredObject target, Map<String, Object> attributes) - { - super(); - _object = target; - _attributes = attributes; - } - - @Override - public Void call() throws Exception - { - _object.setAttributes(_attributes); - return null; - } - - public Map<String, Object> getAttributes() - { - return _attributes; - } - - public ConfiguredObject getObject() - { - return _object; - } - - @Override - public String toString() - { - return "ChangeAttributesTask [object=" + _object + ", attributes=" + _attributes + "]"; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java deleted file mode 100644 index b6de1e136a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.updater; - -import java.util.concurrent.Callable; - -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.State; - -public final class ChangeStateTask implements Callable<State> -{ - private ConfiguredObject _object; - private State _expectedState; - private State _desiredState; - - public ChangeStateTask(ConfiguredObject object, State expectedState, State desiredState) - { - _object = object; - _expectedState = expectedState; - _desiredState = desiredState; - } - - public ConfiguredObject getObject() - { - return _object; - } - - public State getExpectedState() - { - return _expectedState; - } - - public State getDesiredState() - { - return _desiredState; - } - - @Override - public State call() - { - return _object.setDesiredState(_expectedState, _desiredState); - } - - @Override - public String toString() - { - return "ChangeStateTask [object=" + _object + ", expectedState=" + _expectedState + ", desiredState=" + _desiredState + "]"; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java deleted file mode 100644 index d3a8f5b797..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.updater; - -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.Callable; - -import org.apache.qpid.server.model.ConfiguredObject; - -public final class CreateChildTask implements Callable<ConfiguredObject> -{ - private ConfiguredObject _object; - private Class<? extends ConfiguredObject> _childClass; - private Map<String, Object> _attributes; - private ConfiguredObject[] _otherParents; - - public CreateChildTask(ConfiguredObject object, Class<? extends ConfiguredObject> childClass, Map<String, Object> attributes, - ConfiguredObject... otherParents) - { - _object = object; - _childClass = childClass; - _attributes = attributes; - _otherParents = otherParents; - } - - public ConfiguredObject getObject() - { - return _object; - } - - public Class<? extends ConfiguredObject> getChildClass() - { - return _childClass; - } - - public Map<String, Object> getAttributes() - { - return _attributes; - } - - public ConfiguredObject[] getOtherParents() - { - return _otherParents; - } - - @Override - public ConfiguredObject call() - { - return _object.createChild(_childClass, _attributes, _otherParents); - } - - @Override - public String toString() - { - return "CreateChildTask [object=" + _object + ", childClass=" + _childClass + ", attributes=" + _attributes - + ", otherParents=" + Arrays.toString(_otherParents) + "]"; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java deleted file mode 100644 index 94649434e6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.updater; - -import java.util.concurrent.Callable; - -import org.apache.qpid.server.model.ConfiguredObject; - -public final class SetAttributeTask implements Callable<Object> -{ - private ConfiguredObject _object; - private String _attributeName; - private Object _expectedValue; - private Object _desiredValue; - - public SetAttributeTask(ConfiguredObject object, String attributeName, Object expectedValue, Object desiredValue) - { - _object = object; - _attributeName = attributeName; - _expectedValue = expectedValue; - _desiredValue = desiredValue; - } - - public ConfiguredObject getObject() - { - return _object; - } - - public String getAttributeName() - { - return _attributeName; - } - - public Object getExpectedValue() - { - return _expectedValue; - } - - public Object getDesiredValue() - { - return _desiredValue; - } - - @Override - public Object call() - { - return _object.setAttribute(_attributeName, _expectedValue, _desiredValue); - } - - @Override - public String toString() - { - return "SetAttributeTask [object=" + _object + ", attributeName=" + _attributeName + ", expectedValue=" + _expectedValue - + ", desiredValue=" + _desiredValue + "]"; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java deleted file mode 100644 index 671104d413..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.configuration.updater; - -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.RunnableFuture; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import javax.security.auth.Subject; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.security.SecurityManager; - -public class TaskExecutor -{ - private static final String TASK_EXECUTION_THREAD_NAME = "Broker-Configuration-Thread"; - private static final Logger LOGGER = Logger.getLogger(TaskExecutor.class); - - private volatile Thread _taskThread; - private final AtomicReference<State> _state; - private volatile ExecutorService _executor; - - public TaskExecutor() - { - _state = new AtomicReference<State>(State.INITIALISING); - } - - public State getState() - { - return _state.get(); - } - - public void start() - { - if (_state.compareAndSet(State.INITIALISING, State.ACTIVE)) - { - LOGGER.debug("Starting task executor"); - _executor = Executors.newFixedThreadPool(1, new ThreadFactory() - { - @Override - public Thread newThread(Runnable r) - { - _taskThread = new Thread(r, TASK_EXECUTION_THREAD_NAME); - return _taskThread; - } - }); - LOGGER.debug("Task executor is started"); - } - } - - public void stopImmediately() - { - if (_state.compareAndSet(State.ACTIVE, State.STOPPED)) - { - ExecutorService executor = _executor; - if (executor != null) - { - LOGGER.debug("Stopping task executor immediately"); - List<Runnable> cancelledTasks = executor.shutdownNow(); - if (cancelledTasks != null) - { - for (Runnable runnable : cancelledTasks) - { - if (runnable instanceof RunnableFuture<?>) - { - ((RunnableFuture<?>) runnable).cancel(true); - } - } - } - _executor = null; - _taskThread = null; - LOGGER.debug("Task executor was stopped immediately. Number of unfinished tasks: " + cancelledTasks.size()); - } - } - } - - public void stop() - { - if (_state.compareAndSet(State.ACTIVE, State.STOPPED)) - { - ExecutorService executor = _executor; - if (executor != null) - { - LOGGER.debug("Stopping task executor"); - executor.shutdown(); - _executor = null; - _taskThread = null; - LOGGER.debug("Task executor is stopped"); - } - } - } - - Future<?> submit(Callable<?> task) - { - checkState(); - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("Submitting task: " + task); - } - Future<?> future = null; - if (isTaskExecutorThread()) - { - Object result = executeTaskAndHandleExceptions(task); - return new ImmediateFuture(result); - } - else - { - future = _executor.submit(new CallableWrapper(task)); - } - return future; - } - - public Object submitAndWait(Callable<?> task) throws CancellationException - { - try - { - Future<?> future = submit(task); - return future.get(); - } - catch (InterruptedException e) - { - throw new RuntimeException("Task execution was interrupted: " + task, e); - } - catch (ExecutionException e) - { - Throwable cause = e.getCause(); - if (cause instanceof RuntimeException) - { - throw (RuntimeException) cause; - } - else if (cause instanceof Exception) - { - throw new RuntimeException("Failed to execute user task: " + task, cause); - } - else if (cause instanceof Error) - { - throw (Error) cause; - } - else - { - throw new RuntimeException("Failed to execute user task: " + task, cause); - } - } - } - - public boolean isTaskExecutorThread() - { - return Thread.currentThread() == _taskThread; - } - - private void checkState() - { - if (_state.get() != State.ACTIVE) - { - throw new IllegalStateException("Task executor is not in ACTIVE state"); - } - } - - private Object executeTaskAndHandleExceptions(Callable<?> userTask) - { - try - { - return executeTask(userTask); - } - catch (Exception e) - { - if (e instanceof RuntimeException) - { - throw (RuntimeException) e; - } - throw new RuntimeException("Failed to execute user task: " + userTask, e); - } - } - - private Object executeTask(Callable<?> userTask) throws Exception - { - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("Performing task " + userTask); - } - Object result = userTask.call(); - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("Task " + userTask + " is performed successfully with result:" + result); - } - return result; - } - - private class CallableWrapper implements Callable<Object> - { - private Callable<?> _userTask; - private Subject _securityManagerSubject; - private LogActor _actor; - private Subject _contextSubject; - - public CallableWrapper(Callable<?> userWork) - { - _userTask = userWork; - _securityManagerSubject = SecurityManager.getThreadSubject(); - _actor = CurrentActor.get(); - _contextSubject = Subject.getSubject(AccessController.getContext()); - } - - @Override - public Object call() throws Exception - { - SecurityManager.setThreadSubject(_securityManagerSubject); - CurrentActor.set(_actor); - - try - { - Object result = null; - try - { - result = Subject.doAs(_contextSubject, new PrivilegedExceptionAction<Object>() - { - @Override - public Object run() throws Exception - { - return executeTask(_userTask); - } - }); - } - catch (PrivilegedActionException e) - { - throw e.getException(); - } - return result; - } - finally - { - try - { - CurrentActor.remove(); - } - catch (Exception e) - { - LOGGER.warn("Unxpected exception on current actor removal", e); - } - try - { - SecurityManager.setThreadSubject(null); - } - catch (Exception e) - { - LOGGER.warn("Unxpected exception on nullifying of subject for a security manager", e); - } - } - } - } - - private class ImmediateFuture implements Future<Object> - { - private Object _result; - - public ImmediateFuture(Object result) - { - super(); - this._result = result; - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) - { - return false; - } - - @Override - public boolean isCancelled() - { - return false; - } - - @Override - public boolean isDone() - { - return true; - } - - @Override - public Object get() - { - return _result; - } - - @Override - public Object get(long timeout, TimeUnit unit) - { - return get(); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/connection/ConnectionRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/connection/ConnectionRegistry.java deleted file mode 100644 index b933d3f961..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/connection/ConnectionRegistry.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.connection; - -import org.apache.log4j.Logger; - -import org.apache.qpid.common.Closeable; -import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.server.protocol.AMQConnectionModel; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -public class ConnectionRegistry implements IConnectionRegistry, Closeable -{ - private List<AMQConnectionModel> _registry = new CopyOnWriteArrayList<AMQConnectionModel>(); - - private Logger _logger = Logger.getLogger(ConnectionRegistry.class); - private final Collection<RegistryChangeListener> _listeners = - new ArrayList<RegistryChangeListener>(); - - public void initialise() - { - // None required - } - - /** Close all of the currently open connections. */ - public void close() - { - close(IConnectionRegistry.BROKER_SHUTDOWN_REPLY_TEXT); - } - - public void close(final String replyText) - { - synchronized(this) - { - for(AMQConnectionModel conn : _registry) - { - conn.stop(); - } - } - if (_logger.isDebugEnabled()) - { - _logger.debug("Closing connection registry :" + _registry.size() + " connections."); - } - while (!_registry.isEmpty()) - { - AMQConnectionModel connection = _registry.get(0); - closeConnection(connection, AMQConstant.CONNECTION_FORCED, replyText); - } - } - - private void closeConnection(AMQConnectionModel connection, AMQConstant cause, String message) - { - try - { - connection.close(cause, message); - } - catch (Exception e) - { - _logger.warn("Exception closing connection", e); - } - } - - public void registerConnection(AMQConnectionModel connnection) - { - synchronized (this) - { - _registry.add(connnection); - synchronized (_listeners) - { - for(RegistryChangeListener listener : _listeners) - { - listener.connectionRegistered(connnection); - } - } - } - } - - public void deregisterConnection(AMQConnectionModel connnection) - { - synchronized (this) - { - _registry.remove(connnection); - - synchronized (_listeners) - { - for(RegistryChangeListener listener : _listeners) - { - listener.connectionUnregistered(connnection); - } - } - } - } - - public void addRegistryChangeListener(RegistryChangeListener listener) - { - synchronized (_listeners) - { - _listeners.add(listener); - } - } - - public List<AMQConnectionModel> getConnections() - { - synchronized (this) - { - return new ArrayList<AMQConnectionModel>(_registry); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/connection/IConnectionRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/connection/IConnectionRegistry.java deleted file mode 100644 index 07d934027e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/connection/IConnectionRegistry.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.connection; - -import org.apache.qpid.AMQException; -import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.server.protocol.AMQConnectionModel; - -import java.util.List; - -public interface IConnectionRegistry -{ - public static final String BROKER_SHUTDOWN_REPLY_TEXT = "Broker is shutting down"; - public static final String VHOST_PASSIVATE_REPLY_TEXT = "Virtual host is being passivated"; - - public void initialise(); - - public void close() throws AMQException; - - public void close(String replyText); - - public List<AMQConnectionModel> getConnections(); - - public void registerConnection(AMQConnectionModel connnection); - - public void deregisterConnection(AMQConnectionModel connnection); - - void addRegistryChangeListener(RegistryChangeListener listener); - - interface RegistryChangeListener - { - void connectionRegistered(AMQConnectionModel connection); - void connectionUnregistered(AMQConnectionModel connection); - - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java deleted file mode 100644 index c30ebe17be..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java +++ /dev/null @@ -1,679 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.ArrayList; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQInternalException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.BindingMessages; -import org.apache.qpid.server.logging.messages.ExchangeMessages; -import org.apache.qpid.server.logging.subjects.BindingLogSubject; -import org.apache.qpid.server.logging.subjects.ExchangeLogSubject; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.store.DurableConfigurationStoreHelper; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -public abstract class AbstractExchange implements Exchange -{ - private static final Logger _logger = Logger.getLogger(AbstractExchange.class); - private String _name; - private final AtomicBoolean _closed = new AtomicBoolean(); - - private Exchange _alternateExchange; - - private boolean _durable; - - private VirtualHost _virtualHost; - - private final List<Task> _closeTaskList = new CopyOnWriteArrayList<Task>(); - - /** - * Whether the exchange is automatically deleted once all queues have detached from it - */ - private boolean _autoDelete; - - //The logSubject for ths exchange - private LogSubject _logSubject; - private Map<ExchangeReferrer,Object> _referrers = new ConcurrentHashMap<ExchangeReferrer,Object>(); - - private final CopyOnWriteArrayList<Binding> _bindings = new CopyOnWriteArrayList<Binding>(); - private final ExchangeType<? extends Exchange> _type; - private UUID _id; - private final AtomicInteger _bindingCountHigh = new AtomicInteger(); - private final AtomicLong _receivedMessageCount = new AtomicLong(); - private final AtomicLong _receivedMessageSize = new AtomicLong(); - private final AtomicLong _routedMessageCount = new AtomicLong(); - private final AtomicLong _routedMessageSize = new AtomicLong(); - private final AtomicLong _droppedMessageCount = new AtomicLong(); - private final AtomicLong _droppedMessageSize = new AtomicLong(); - - private final CopyOnWriteArrayList<Exchange.BindingListener> _listeners = new CopyOnWriteArrayList<Exchange.BindingListener>(); - - //TODO : persist creation time - private long _createTime = System.currentTimeMillis(); - - public AbstractExchange(final ExchangeType<? extends Exchange> type) - { - _type = type; - } - - @Override - public String getTypeName() - { - return _type.getType(); - } - - public void initialise(UUID id, - VirtualHost host, - String name, - boolean durable, - boolean autoDelete) - throws AMQException - { - _virtualHost = host; - _name = name; - _durable = durable; - _autoDelete = autoDelete; - - _id = id; - _logSubject = new ExchangeLogSubject(this, this.getVirtualHost()); - - // Log Exchange creation - CurrentActor.get().message(ExchangeMessages.CREATED(getType().getType(), name, durable)); - } - - public boolean isDurable() - { - return _durable; - } - - public boolean isAutoDelete() - { - return _autoDelete; - } - - public void close() throws AMQException - { - - if(_closed.compareAndSet(false,true)) - { - if(_alternateExchange != null) - { - _alternateExchange.removeReference(this); - } - - CurrentActor.get().message(_logSubject, ExchangeMessages.DELETED()); - - for(Task task : _closeTaskList) - { - task.onClose(this); - } - _closeTaskList.clear(); - } - } - - public String toString() - { - return getClass().getSimpleName() + "[" + getName() +"]"; - } - - public VirtualHost getVirtualHost() - { - return _virtualHost; - } - - public final boolean isBound(String bindingKey, Map<String,Object> arguments, AMQQueue queue) - { - for(Binding b : _bindings) - { - if(bindingKey.equals(b.getBindingKey()) && queue == b.getQueue()) - { - return (b.getArguments() == null || b.getArguments().isEmpty()) - ? (arguments == null || arguments.isEmpty()) - : b.getArguments().equals(arguments); - } - } - return false; - } - - public final boolean isBound(String bindingKey, AMQQueue queue) - { - for(Binding b : _bindings) - { - if(bindingKey.equals(b.getBindingKey()) && queue == b.getQueue()) - { - return true; - } - } - return false; - } - - public final boolean isBound(String bindingKey) - { - for(Binding b : _bindings) - { - if(bindingKey.equals(b.getBindingKey())) - { - return true; - } - } - return false; - } - - public final boolean isBound(AMQQueue queue) - { - for(Binding b : _bindings) - { - if(queue == b.getQueue()) - { - return true; - } - } - return false; - } - - @Override - public final boolean isBound(Map<String, Object> arguments, AMQQueue queue) - { - for(Binding b : _bindings) - { - if(queue == b.getQueue() && - ((b.getArguments() == null || b.getArguments().isEmpty()) - ? (arguments == null || arguments.isEmpty()) - : b.getArguments().equals(arguments))) - { - return true; - } - } - return false; - } - - - public final boolean isBound(Map<String, Object> arguments) - { - for(Binding b : _bindings) - { - if(((b.getArguments() == null || b.getArguments().isEmpty()) - ? (arguments == null || arguments.isEmpty()) - : b.getArguments().equals(arguments))) - { - return true; - } - } - return false; - } - - - @Override - public final boolean isBound(String bindingKey, Map<String, Object> arguments) - { - for(Binding b : _bindings) - { - if(b.getBindingKey().equals(bindingKey) && - ((b.getArguments() == null || b.getArguments().isEmpty()) - ? (arguments == null || arguments.isEmpty()) - : b.getArguments().equals(arguments))) - { - return true; - } - } - return false; - } - - public final boolean hasBindings() - { - return !_bindings.isEmpty(); - } - - public Exchange getAlternateExchange() - { - return _alternateExchange; - } - - public void setAlternateExchange(Exchange exchange) - { - if(_alternateExchange != null) - { - _alternateExchange.removeReference(this); - } - if(exchange != null) - { - exchange.addReference(this); - } - _alternateExchange = exchange; - - } - - public void removeReference(ExchangeReferrer exchange) - { - _referrers.remove(exchange); - } - - public void addReference(ExchangeReferrer exchange) - { - _referrers.put(exchange, Boolean.TRUE); - } - - public boolean hasReferrers() - { - return !_referrers.isEmpty(); - } - - public void addCloseTask(final Task task) - { - _closeTaskList.add(task); - } - - public void removeCloseTask(final Task task) - { - _closeTaskList.remove(task); - } - - public final void doAddBinding(final Binding binding) - { - _bindings.add(binding); - int bindingCountSize = _bindings.size(); - int maxBindingsSize; - while((maxBindingsSize = _bindingCountHigh.get()) < bindingCountSize) - { - _bindingCountHigh.compareAndSet(maxBindingsSize, bindingCountSize); - } - for(BindingListener listener : _listeners) - { - listener.bindingAdded(this, binding); - } - onBind(binding); - } - - public long getBindingCountHigh() - { - return _bindingCountHigh.get(); - } - - public final void doRemoveBinding(final Binding binding) - { - onUnbind(binding); - for(BindingListener listener : _listeners) - { - listener.bindingRemoved(this, binding); - } - _bindings.remove(binding); - } - - public final Collection<Binding> getBindings() - { - return Collections.unmodifiableList(_bindings); - } - - protected abstract void onBind(final Binding binding); - - protected abstract void onUnbind(final Binding binding); - - - public String getName() - { - return _name.toString(); - } - - public ExchangeType getType() - { - return _type; - } - - public Map<String, Object> getArguments() - { - return Collections.emptyMap(); - } - - public UUID getId() - { - return _id; - } - - public long getBindingCount() - { - return getBindings().size(); - } - - public final List<? extends BaseQueue> route(final InboundMessage message) - { - _receivedMessageCount.incrementAndGet(); - _receivedMessageSize.addAndGet(message.getSize()); - List<? extends BaseQueue> queues = doRoute(message); - List<? extends BaseQueue> allQueues = queues; - - boolean deletedQueues = false; - - for(BaseQueue q : allQueues) - { - if(q.isDeleted()) - { - if(!deletedQueues) - { - deletedQueues = true; - queues = new ArrayList<BaseQueue>(allQueues); - } - if(_logger.isDebugEnabled()) - { - _logger.debug("Exchange: " + getName() + " - attempt to enqueue message onto deleted queue " + q.getName()); - } - queues.remove(q); - } - } - - - if(!queues.isEmpty()) - { - _routedMessageCount.incrementAndGet(); - _routedMessageSize.addAndGet(message.getSize()); - } - else - { - _droppedMessageCount.incrementAndGet(); - _droppedMessageSize.addAndGet(message.getSize()); - } - return queues; - } - - protected abstract List<? extends BaseQueue> doRoute(final InboundMessage message); - - public long getMsgReceives() - { - return _receivedMessageCount.get(); - } - - public long getMsgRoutes() - { - return _routedMessageCount.get(); - } - - public long getMsgDrops() - { - return _droppedMessageCount.get(); - } - - public long getByteReceives() - { - return _receivedMessageSize.get(); - } - - public long getByteRoutes() - { - return _routedMessageSize.get(); - } - - public long getByteDrops() - { - return _droppedMessageSize.get(); - } - - public long getCreateTime() - { - return _createTime; - } - - public void addBindingListener(final BindingListener listener) - { - _listeners.add(listener); - } - - public void removeBindingListener(final BindingListener listener) - { - _listeners.remove(listener); - } - - @Override - public boolean addBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException - { - return makeBinding(null, bindingKey, queue, arguments, false, false); - } - - @Override - public boolean replaceBinding(final UUID id, final String bindingKey, - final AMQQueue queue, - final Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException - { - return makeBinding(id, bindingKey, queue, arguments, false, true); - } - - @Override - public void restoreBinding(final UUID id, final String bindingKey, final AMQQueue queue, - final Map<String, Object> argumentMap) - throws AMQSecurityException, AMQInternalException - { - makeBinding(id, bindingKey,queue, argumentMap,true, false); - } - - @Override - public void removeBinding(final Binding b) throws AMQSecurityException, AMQInternalException - { - removeBinding(b.getBindingKey(), b.getQueue(), b.getArguments()); - } - - @Override - public Binding removeBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException - { - assert queue != null; - - if (bindingKey == null) - { - bindingKey = ""; - } - if (arguments == null) - { - arguments = Collections.emptyMap(); - } - - // The default exchange bindings must reflect the existence of queues, allow - // all operations on it to succeed. It is up to the broker to prevent illegal - // attempts at binding to this exchange, not the ACLs. - // Check access - if (!_virtualHost.getSecurityManager().authoriseUnbind(this, bindingKey, queue)) - { - throw new AMQSecurityException("Permission denied: unbinding " + bindingKey); - } - - BindingImpl b = _bindingsMap.remove(new BindingImpl(null, bindingKey,queue,arguments)); - - if (b != null) - { - doRemoveBinding(b); - queue.removeBinding(b); - removeCloseTask(b); - queue.removeQueueDeleteTask(b); - - if (b.isDurable()) - { - DurableConfigurationStoreHelper.removeBinding(_virtualHost.getDurableConfigurationStore(), b); - } - b.logDestruction(); - } - - return b; - } - - - @Override - public Binding getBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments) - { - assert queue != null; - - if(bindingKey == null) - { - bindingKey = ""; - } - - if(arguments == null) - { - arguments = Collections.emptyMap(); - } - - BindingImpl b = new BindingImpl(null, bindingKey,queue,arguments); - return _bindingsMap.get(b); - } - - private final ConcurrentHashMap<BindingImpl, BindingImpl> _bindingsMap = new ConcurrentHashMap<BindingImpl, BindingImpl>(); - - private boolean makeBinding(UUID id, - String bindingKey, - AMQQueue queue, - Map<String, Object> arguments, - boolean restore, - boolean force) throws AMQSecurityException, AMQInternalException - { - assert queue != null; - - if (bindingKey == null) - { - bindingKey = ""; - } - if (arguments == null) - { - arguments = Collections.emptyMap(); - } - - //Perform ACLs - if (!_virtualHost.getSecurityManager().authoriseBind(AbstractExchange.this, queue, bindingKey)) - { - throw new AMQSecurityException("Permission denied: binding " + bindingKey); - } - - if (id == null) - { - id = UUIDGenerator.generateBindingUUID(getName(), - queue.getName(), - bindingKey, - _virtualHost.getName()); - } - BindingImpl b = new BindingImpl(id, bindingKey, queue, arguments); - BindingImpl existingMapping = _bindingsMap.putIfAbsent(b, b); - if (existingMapping == null || force) - { - if (existingMapping != null) - { - removeBinding(existingMapping); - } - - if (b.isDurable() && !restore) - { - DurableConfigurationStoreHelper.createBinding(_virtualHost.getDurableConfigurationStore(), b); - } - - queue.addQueueDeleteTask(b); - addCloseTask(b); - queue.addBinding(b); - doAddBinding(b); - b.logCreation(); - - return true; - } - else - { - return false; - } - } - - private final class BindingImpl extends Binding implements AMQQueue.Task, Task - { - private final BindingLogSubject _logSubject; - //TODO : persist creation time - private long _createTime = System.currentTimeMillis(); - - private BindingImpl(UUID id, - String bindingKey, - final AMQQueue queue, - final Map<String, Object> arguments) - { - super(id, bindingKey, queue, AbstractExchange.this, arguments); - _logSubject = new BindingLogSubject(bindingKey,AbstractExchange.this,queue); - - } - - - public void doTask(final AMQQueue queue) throws AMQException - { - removeBinding(this); - } - - public void onClose(final Exchange exchange) throws AMQSecurityException, AMQInternalException - { - removeBinding(this); - } - - void logCreation() - { - CurrentActor.get().message(_logSubject, BindingMessages.CREATED(String.valueOf(getArguments()), - getArguments() != null - && !getArguments().isEmpty())); - } - - void logDestruction() - { - CurrentActor.get().message(_logSubject, BindingMessages.DELETED()); - } - - public String getOrigin() - { - return (String) getArguments().get("qpid.fed.origin"); - } - - public long getCreateTime() - { - return _createTime; - } - - public boolean isDurable() - { - return getQueue().isDurable() && getExchange().isDurable(); - } - - } - - public static interface Task - { - public void onClose(Exchange exchange) throws AMQSecurityException, AMQInternalException; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchange.java deleted file mode 100644 index aed2ddb8cf..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchange.java +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQInternalException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.ExchangeMessages; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.QueueRegistry; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public class DefaultExchange implements Exchange -{ - - private final QueueRegistry _queueRegistry; - private UUID _id; - private VirtualHost _virtualHost; - private static final Logger _logger = Logger.getLogger(DefaultExchange.class); - private final AtomicBoolean _closed = new AtomicBoolean(); - - private LogSubject _logSubject; - private Map<ExchangeReferrer,Object> _referrers = new ConcurrentHashMap<ExchangeReferrer,Object>(); - - public DefaultExchange(QueueRegistry queueRegistry) - { - _queueRegistry = queueRegistry; - } - - - @Override - public void initialise(UUID id, - VirtualHost host, - String name, - boolean durable, - boolean autoDelete) throws AMQException - { - _id = id; - _virtualHost = host; - } - - @Override - public String getName() - { - return ExchangeDefaults.DEFAULT_EXCHANGE_NAME; - } - - @Override - public ExchangeType getType() - { - return DirectExchange.TYPE; - } - - @Override - public long getBindingCount() - { - return _virtualHost.getQueues().size(); - } - - @Override - public long getByteDrops() - { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public long getByteReceives() - { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public long getMsgDrops() - { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public long getMsgReceives() - { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public boolean addBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException - { - throw new AMQSecurityException("Cannot add bindings to the default exchange"); - } - - @Override - public boolean replaceBinding(UUID id, String bindingKey, AMQQueue queue, Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException - { - throw new AMQSecurityException("Cannot replace bindings on the default exchange"); - } - - @Override - public void restoreBinding(UUID id, String bindingKey, AMQQueue queue, Map<String, Object> argumentMap) - throws AMQSecurityException, AMQInternalException - { - _logger.warn("Bindings to the default exchange should not be stored in the configuration store"); - } - - @Override - public void removeBinding(Binding b) throws AMQSecurityException, AMQInternalException - { - throw new AMQSecurityException("Cannot remove bindings to the default exchange"); - } - - @Override - public Binding removeBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException - { - throw new AMQSecurityException("Cannot remove bindings to the default exchange"); - } - - @Override - public Binding getBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments) - { - if(_virtualHost.getQueue(bindingKey) == queue && (arguments == null || arguments.isEmpty())) - { - return convertToBinding(queue); - } - else - { - return null; - } - - } - - private Binding convertToBinding(AMQQueue queue) - { - String queueName = queue.getName(); - - UUID exchangeId = UUIDGenerator.generateBindingUUID(ExchangeDefaults.DEFAULT_EXCHANGE_NAME, - queueName, - queueName, - _virtualHost.getName()); - - return new Binding(exchangeId, queueName, queue, this, Collections.EMPTY_MAP); - } - - @Override - public String getTypeName() - { - return getType().getType(); - } - - @Override - public boolean isDurable() - { - return false; - } - - @Override - public boolean isAutoDelete() - { - return false; - } - - @Override - public void close() throws AMQException - { - if(_closed.compareAndSet(false,true)) - { - - CurrentActor.get().message(_logSubject, ExchangeMessages.DELETED()); - - } - } - - @Override - public List<AMQQueue> route(InboundMessage message) - { - AMQQueue q = _virtualHost.getQueue(message.getRoutingKey()); - if(q == null) - { - List<AMQQueue> noQueues = Collections.emptyList(); - return noQueues; - } - else - { - return Collections.singletonList(q); - } - - } - - @Override - public boolean isBound(AMQQueue queue) - { - return _virtualHost.getQueue(queue.getName()) == queue; - } - - @Override - public boolean hasBindings() - { - return getBindingCount() != 0; - } - - @Override - public boolean isBound(String bindingKey, AMQQueue queue) - { - return isBound(queue) && queue.getName().equals(bindingKey); - } - - @Override - public boolean isBound(String bindingKey, Map<String, Object> arguments, AMQQueue queue) - { - return isBound(bindingKey, queue) && (arguments == null || arguments.isEmpty()); - } - - @Override - public boolean isBound(Map<String, Object> arguments, AMQQueue queue) - { - return (arguments == null || arguments.isEmpty()) && isBound(queue); - } - - @Override - public boolean isBound(String bindingKey, Map<String, Object> arguments) - { - return (arguments == null || arguments.isEmpty()) && isBound(bindingKey); - } - - @Override - public boolean isBound(Map<String, Object> arguments) - { - return (arguments == null || arguments.isEmpty()) && hasBindings(); - } - - @Override - public boolean isBound(String bindingKey) - { - return _virtualHost.getQueue(bindingKey) != null; - } - - @Override - public Exchange getAlternateExchange() - { - return null; - } - - @Override - public void setAlternateExchange(Exchange exchange) - { - _logger.warn("Cannot set the alternate exchange for the default exchange"); - } - - @Override - public void removeReference(ExchangeReferrer exchange) - { - _referrers.remove(exchange); - } - - @Override - public void addReference(ExchangeReferrer exchange) - { - _referrers.put(exchange, Boolean.TRUE); - } - - @Override - public boolean hasReferrers() - { - return !_referrers.isEmpty(); - } - - @Override - public Collection<Binding> getBindings() - { - List<Binding> bindings = new ArrayList<Binding>(); - for(AMQQueue q : _virtualHost.getQueues()) - { - bindings.add(convertToBinding(q)); - } - return bindings; - } - - @Override - public void addBindingListener(BindingListener listener) - { - _queueRegistry.addRegistryChangeListener(convertListener(listener)); - } - - private QueueRegistry.RegistryChangeListener convertListener(final BindingListener listener) - { - return new QueueRegistry.RegistryChangeListener() - { - @Override - public void queueRegistered(AMQQueue queue) - { - listener.bindingAdded(DefaultExchange.this, convertToBinding(queue)); - } - - @Override - public void queueUnregistered(AMQQueue queue) - { - listener.bindingRemoved(DefaultExchange.this, convertToBinding(queue)); - } - }; - } - - @Override - public void removeBindingListener(BindingListener listener) - { - // TODO - } - - @Override - public UUID getId() - { - return _id; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java deleted file mode 100644 index 612fa855a4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.AMQUnknownExchangeType; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.plugin.QpidServiceLoader; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class DefaultExchangeFactory implements ExchangeFactory -{ - public static final String DEFAULT_DLE_NAME_SUFFIX = "_DLE"; - - private static final Logger LOGGER = Logger.getLogger(DefaultExchangeFactory.class); - - private static final String[] BASE_EXCHANGE_TYPES = - new String[]{ExchangeDefaults.DIRECT_EXCHANGE_CLASS, - ExchangeDefaults.FANOUT_EXCHANGE_CLASS, - ExchangeDefaults.HEADERS_EXCHANGE_CLASS, - ExchangeDefaults.TOPIC_EXCHANGE_CLASS}; - - private final VirtualHost _host; - private Map<String, ExchangeType<? extends Exchange>> _exchangeClassMap = new HashMap<String, ExchangeType<? extends Exchange>>(); - - public DefaultExchangeFactory(VirtualHost host) - { - _host = host; - - @SuppressWarnings("rawtypes") - Iterable<ExchangeType> exchangeTypes = loadExchangeTypes(); - for (ExchangeType<?> exchangeType : exchangeTypes) - { - String typeName = exchangeType.getType(); - - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("Registering exchange type '" + typeName + "' using class '" + exchangeType.getClass().getName() + "'"); - } - - if(_exchangeClassMap.containsKey(typeName)) - { - ExchangeType<?> existingType = _exchangeClassMap.get(typeName); - - throw new IllegalStateException("ExchangeType with type name '" + typeName + "' is already registered using class '" - + existingType.getClass().getName() + "', can not register class '" - + exchangeType.getClass().getName() + "'"); - } - - _exchangeClassMap.put(typeName, exchangeType); - } - - for(String type : BASE_EXCHANGE_TYPES) - { - if(!_exchangeClassMap.containsKey(type)) - { - throw new IllegalStateException("Did not find expected exchange type: " + type); - } - } - } - - @SuppressWarnings("rawtypes") - protected Iterable<ExchangeType> loadExchangeTypes() - { - return new QpidServiceLoader<ExchangeType>().atLeastOneInstanceOf(ExchangeType.class); - } - - public Collection<ExchangeType<? extends Exchange>> getRegisteredTypes() - { - return _exchangeClassMap.values(); - } - - public Collection<ExchangeType<? extends Exchange>> getPublicCreatableTypes() - { - Collection<ExchangeType<? extends Exchange>> publicTypes = - new ArrayList<ExchangeType<? extends Exchange>>(); - publicTypes.addAll(_exchangeClassMap.values()); - - return publicTypes; - } - - public Exchange createExchange(String exchange, String type, boolean durable, boolean autoDelete) - throws AMQException - { - - UUID id = UUIDGenerator.generateExchangeUUID(exchange, _host.getName()); - return createExchange(id, exchange, type, durable, autoDelete); - } - - public Exchange createExchange(UUID id, String exchange, String type, boolean durable, boolean autoDelete) - throws AMQException - { - // Check access - if (!_host.getSecurityManager().authoriseCreateExchange(autoDelete, durable, exchange, null, null, null, type)) - { - String description = "Permission denied: exchange-name '" + exchange + "'"; - throw new AMQSecurityException(description); - } - - ExchangeType<? extends Exchange> exchType = _exchangeClassMap.get(type); - if (exchType == null) - { - throw new AMQUnknownExchangeType("Unknown exchange type: " + type,null); - } - - Exchange e = exchType.newInstance(id, _host, exchange, durable, autoDelete); - return e; - } - - @Override - public Exchange restoreExchange(UUID id, String exchange, String type, boolean autoDelete) throws AMQException - { - return createExchange(id, exchange, type, true, autoDelete); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java deleted file mode 100644 index b54f995b5e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.queue.QueueRegistry; -import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -public class DefaultExchangeRegistry implements ExchangeRegistry -{ - private static final Logger LOGGER = Logger.getLogger(DefaultExchangeRegistry.class); - /** - * Maps from exchange name to exchange instance - */ - private ConcurrentMap<String, Exchange> _exchangeMap = new ConcurrentHashMap<String, Exchange>(); - - private Exchange _defaultExchange; - - private final VirtualHost _host; - private final QueueRegistry _queueRegistry; - - private final Collection<RegistryChangeListener> _listeners = - Collections.synchronizedCollection(new ArrayList<RegistryChangeListener>()); - - public DefaultExchangeRegistry(VirtualHost host, QueueRegistry queueRegistry) - { - _host = host; - _queueRegistry = queueRegistry; - } - - public void initialise(ExchangeFactory exchangeFactory) throws AMQException - { - //create 'standard' exchanges: - new ExchangeInitialiser().initialise(exchangeFactory, this, getDurableConfigurationStore()); - - _defaultExchange = new DefaultExchange(_queueRegistry); - - UUID defaultExchangeId = - UUIDGenerator.generateExchangeUUID(ExchangeDefaults.DEFAULT_EXCHANGE_NAME, _host.getName()); - - _defaultExchange.initialise(defaultExchangeId, _host, ExchangeDefaults.DEFAULT_EXCHANGE_NAME,false, false); - - } - - public DurableConfigurationStore getDurableConfigurationStore() - { - return _host.getDurableConfigurationStore(); - } - - public void registerExchange(Exchange exchange) throws AMQException - { - _exchangeMap.put(exchange.getName(), exchange); - synchronized (_listeners) - { - for(RegistryChangeListener listener : _listeners) - { - listener.exchangeRegistered(exchange); - } - - } - } - - public void setDefaultExchange(Exchange exchange) - { - _defaultExchange = exchange; - } - - public Exchange getDefaultExchange() - { - return _defaultExchange; - } - - public void unregisterExchange(String name, boolean inUse) throws AMQException - { - final Exchange exchange = _exchangeMap.get(name); - if (exchange == null) - { - throw new AMQException(AMQConstant.NOT_FOUND, "Unknown exchange " + name, null); - } - - if (!_host.getSecurityManager().authoriseDelete(exchange)) - { - throw new AMQSecurityException(); - } - - // TODO: check inUse argument - - Exchange e = _exchangeMap.remove(name); - if (e != null) - { - e.close(); - - synchronized (_listeners) - { - for(RegistryChangeListener listener : _listeners) - { - listener.exchangeUnregistered(exchange); - } - } - - } - else - { - throw new AMQException("Unknown exchange " + name); - } - } - - public Collection<Exchange> getExchanges() - { - return new ArrayList<Exchange>(_exchangeMap.values()); - } - - public void addRegistryChangeListener(RegistryChangeListener listener) - { - _listeners.add(listener); - } - - public Exchange getExchange(String name) - { - if ((name == null) || name.length() == 0) - { - return getDefaultExchange(); - } - else - { - return _exchangeMap.get(name); - } - } - - @Override - public void clearAndUnregisterMbeans() - { - for (final Exchange exchange : getExchanges()) - { - //TODO: this is a bit of a hack, what if the listeners aren't aware - //that we are just unregistering the MBean because of HA, and aren't - //actually removing the exchange as such. - synchronized (_listeners) - { - for(RegistryChangeListener listener : _listeners) - { - listener.exchangeUnregistered(exchange); - } - } - } - _exchangeMap.clear(); - } - - @Override - public synchronized Exchange getExchange(UUID exchangeId) - { - if (exchangeId == null) - { - return getDefaultExchange(); - } - else - { - Collection<Exchange> exchanges = _exchangeMap.values(); - for (Exchange exchange : exchanges) - { - if (exchange.getId().equals(exchangeId)) - { - return exchange; - } - } - return null; - } - } - - public boolean isReservedExchangeName(String name) - { - if (name == null || ExchangeDefaults.DEFAULT_EXCHANGE_NAME.equals(name) - || name.startsWith("amq.") || name.startsWith("qpid.")) - { - return true; - } - Collection<ExchangeType<? extends Exchange>> registeredTypes = _host.getExchangeTypes(); - for (ExchangeType<? extends Exchange> type : registeredTypes) - { - if (type.getDefaultExchangeName().equals(name)) - { - return true; - } - } - return false; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java deleted file mode 100644 index 1e022c994e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQInvalidArgumentException; -import org.apache.qpid.common.AMQPFilterTypes; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.filter.JMSSelectorFilter; -import org.apache.qpid.server.filter.MessageFilter; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.BaseQueue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArraySet; - -public class DirectExchange extends AbstractExchange -{ - - private static final Logger _logger = Logger.getLogger(DirectExchange.class); - - private static final class BindingSet - { - private CopyOnWriteArraySet<Binding> _bindings = new CopyOnWriteArraySet<Binding>(); - private List<BaseQueue> _unfilteredQueues = new ArrayList<BaseQueue>(); - private Map<BaseQueue, MessageFilter> _filteredQueues = new HashMap<BaseQueue, MessageFilter>(); - - public synchronized void addBinding(Binding binding) - { - _bindings.add(binding); - recalculateQueues(); - } - - public synchronized void removeBinding(Binding binding) - { - _bindings.remove(binding); - recalculateQueues(); - } - - private void recalculateQueues() - { - List<BaseQueue> queues = new ArrayList<BaseQueue>(_bindings.size()); - Map<BaseQueue, MessageFilter> filteredQueues = new HashMap<BaseQueue,MessageFilter>(); - - for(Binding b : _bindings) - { - - if(FilterSupport.argumentsContainFilter(b.getArguments())) - { - try - { - MessageFilter filter = FilterSupport.createMessageFilter(b.getArguments(), b.getQueue()); - filteredQueues.put(b.getQueue(),filter); - } - catch (AMQInvalidArgumentException e) - { - _logger.warn("Binding ignored: cannot parse filter on binding of queue '"+b.getQueue().getName() - + "' to exchange '" + b.getExchange().getName() - + "' with arguments: " + b.getArguments(), e); - } - - } - else - { - - if(!queues.contains(b.getQueue())) - { - queues.add(b.getQueue()); - } - } - } - _unfilteredQueues = queues; - _filteredQueues = filteredQueues; - } - - - public List<BaseQueue> getUnfilteredQueues() - { - return _unfilteredQueues; - } - - public CopyOnWriteArraySet<Binding> getBindings() - { - return _bindings; - } - - public boolean hasFilteredQueues() - { - return !_filteredQueues.isEmpty(); - } - - public Map<BaseQueue,MessageFilter> getFilteredQueues() - { - return _filteredQueues; - } - } - - private final ConcurrentHashMap<String, BindingSet> _bindingsByKey = - new ConcurrentHashMap<String, BindingSet>(); - - public static final ExchangeType<DirectExchange> TYPE = new DirectExchangeType(); - - public DirectExchange() - { - super(TYPE); - } - - public List<? extends BaseQueue> doRoute(InboundMessage payload) - { - - final String routingKey = payload.getRoutingKey(); - - BindingSet bindings = _bindingsByKey.get(routingKey == null ? "" : routingKey); - - if(bindings != null) - { - List<BaseQueue> queues = bindings.getUnfilteredQueues(); - - if(bindings.hasFilteredQueues()) - { - Set<BaseQueue> queuesSet = new HashSet<BaseQueue>(queues); - - Map<BaseQueue, MessageFilter> filteredQueues = bindings.getFilteredQueues(); - for(Map.Entry<BaseQueue, MessageFilter> entry : filteredQueues.entrySet()) - { - if(!queuesSet.contains(entry.getKey())) - { - MessageFilter filter = entry.getValue(); - if(filter.matches(payload)) - { - queuesSet.add(entry.getKey()); - } - } - } - if(queues.size() != queuesSet.size()) - { - queues = new ArrayList<BaseQueue>(queuesSet); - } - } - return queues; - } - else - { - return Collections.emptyList(); - } - - - } - - protected void onBind(final Binding binding) - { - String bindingKey = binding.getBindingKey(); - AMQQueue queue = binding.getQueue(); - - assert queue != null; - assert bindingKey != null; - - BindingSet bindings = _bindingsByKey.get(bindingKey); - - if(bindings == null) - { - bindings = new BindingSet(); - BindingSet newBindings; - if((newBindings = _bindingsByKey.putIfAbsent(bindingKey, bindings)) != null) - { - bindings = newBindings; - } - } - - bindings.addBinding(binding); - - } - - protected void onUnbind(final Binding binding) - { - assert binding != null; - - BindingSet bindings = _bindingsByKey.get(binding.getBindingKey()); - if(bindings != null) - { - bindings.removeBinding(binding); - } - - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java deleted file mode 100644 index d61d10155e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.UUID; - -import org.apache.qpid.AMQException; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public class DirectExchangeType implements ExchangeType<DirectExchange> -{ - @Override - public String getType() - { - return ExchangeDefaults.DIRECT_EXCHANGE_CLASS; - } - - public DirectExchange newInstance(UUID id, VirtualHost host, - String name, - boolean durable, - boolean autoDelete) throws AMQException - { - DirectExchange exch = new DirectExchange(); - exch.initialise(id, host,name,durable, autoDelete); - return exch; - } - - public String getDefaultExchangeName() - { - return ExchangeDefaults.DIRECT_EXCHANGE_NAME; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java deleted file mode 100644 index d05e731daa..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQInternalException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public interface Exchange extends ExchangeReferrer -{ - void initialise(UUID id, VirtualHost host, String name, boolean durable, boolean autoDelete) - throws AMQException; - - - UUID getId(); - - String getName(); - - ExchangeType getType(); - - String getTypeName(); - - boolean isDurable(); - - /** - * @return true if the exchange will be deleted after all queues have been detached - */ - boolean isAutoDelete(); - - Exchange getAlternateExchange(); - - void setAlternateExchange(Exchange exchange); - - long getBindingCount(); - - long getByteDrops(); - - long getByteReceives(); - - long getMsgDrops(); - - long getMsgReceives(); - - - boolean addBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException; - - boolean replaceBinding(UUID id, String bindingKey, - AMQQueue queue, - Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException; - - void restoreBinding(UUID id, String bindingKey, AMQQueue queue, - Map<String, Object> argumentMap) - throws AMQSecurityException, AMQInternalException; - - void removeBinding(Binding b) throws AMQSecurityException, AMQInternalException; - - Binding removeBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments) - throws AMQSecurityException, AMQInternalException; - - Binding getBinding(String bindingKey, AMQQueue queue, Map<String, Object> arguments); - - void close() throws AMQException; - - /** - * Returns a list of queues to which to route this message. If there are - * no queues the empty list must be returned. - * - * @return list of queues to which to route the message. - */ - List<? extends BaseQueue> route(InboundMessage message); - - - /** - * Determines whether a message would be isBound to a particular queue using a specific routing key and arguments - * @param bindingKey - * @param arguments - * @param queue - * @return - * @throws AMQException - */ - - boolean isBound(String bindingKey, Map<String,Object> arguments, AMQQueue queue); - - /** - * Determines whether a message would be isBound to a particular queue using a specific routing key - * @param bindingKey - * @param queue - * @return - * @throws AMQException - */ - - boolean isBound(String bindingKey, AMQQueue queue); - - /** - * Determines whether a message is routing to any queue using a specific _routing key - * @param bindingKey - * @return - * @throws AMQException - */ - boolean isBound(String bindingKey); - - /** - * Returns true if this exchange has at least one binding associated with it. - * @return - * @throws AMQException - */ - boolean hasBindings(); - - Collection<Binding> getBindings(); - - boolean isBound(AMQQueue queue); - - boolean isBound(Map<String, Object> arguments); - - boolean isBound(String bindingKey, Map<String, Object> arguments); - - boolean isBound(Map<String, Object> arguments, AMQQueue queue); - - void removeReference(ExchangeReferrer exchange); - - void addReference(ExchangeReferrer exchange); - - boolean hasReferrers(); - - - - public interface BindingListener - { - void bindingAdded(Exchange exchange, Binding binding); - void bindingRemoved(Exchange exchange, Binding binding); - } - - public void addBindingListener(BindingListener listener); - - public void removeBindingListener(BindingListener listener); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java deleted file mode 100644 index f364691666..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.plugin.ExchangeType; - -import java.util.Collection; -import java.util.UUID; - - -public interface ExchangeFactory -{ - - Collection<ExchangeType<? extends Exchange>> getRegisteredTypes(); - - Collection<ExchangeType<? extends Exchange>> getPublicCreatableTypes(); - - Exchange createExchange(String exchange, String type, boolean durable, boolean autoDelete) throws AMQException; - - Exchange createExchange(UUID id, String exchange, String type, boolean durable, boolean autoDelete) throws AMQException; - Exchange restoreExchange(UUID id, String exchange, String type, boolean autoDelete) throws AMQException; - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInUseException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInUseException.java deleted file mode 100644 index c77f114428..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInUseException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import org.apache.qpid.AMQException; - -/** - * ExchangeInUseRegistry indicates that an exchange cannot be unregistered because it is currently being used. - * - * <p/><table id="crc"><caption>CRC Card</caption> - * <tr><th> Responsibilities <th> Collaborations - * <tr><td> Represents failure to unregister exchange that is in use. - * </table> - * - * @todo Not an AMQP exception as no status code. - * - * @todo This exception is not used. However, it is part of the ExchangeRegistry interface, and looks like code is - * going to need to be added to throw/deal with this. Alternatively ExchangeResitries may be able to handle the - * issue internally. - */ -public class ExchangeInUseException extends AMQException -{ - public ExchangeInUseException(String exchangeName) - { - super("Exchange " + exchangeName + " is currently in use"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java deleted file mode 100644 index 6dbc1d54d1..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.store.DurableConfigurationStoreHelper; -import org.apache.qpid.server.store.DurableConfigurationStore; - -public class ExchangeInitialiser -{ - public void initialise(ExchangeFactory factory, ExchangeRegistry registry, DurableConfigurationStore store) throws AMQException - { - for (ExchangeType<? extends Exchange> type : factory.getRegisteredTypes()) - { - define (registry, factory, type.getDefaultExchangeName(), type.getType(), store); - } - - } - - private void define(ExchangeRegistry r, ExchangeFactory f, - String name, String type, DurableConfigurationStore store) throws AMQException - { - if(r.getExchange(name)== null) - { - Exchange exchange = f.createExchange(name, type, true, false); - r.registerExchange(exchange); - if(exchange.isDurable()) - { - DurableConfigurationStoreHelper.createExchange(store, exchange); - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeReferrer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeReferrer.java deleted file mode 100755 index e41d63d97d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeReferrer.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -public interface ExchangeReferrer -{ -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeRegistry.java deleted file mode 100644 index 53ee7de661..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeRegistry.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQShortString; - -import java.util.Collection; -import java.util.UUID; - - -public interface ExchangeRegistry -{ - void registerExchange(Exchange exchange) throws AMQException; - - Exchange getDefaultExchange(); - - void initialise(ExchangeFactory exchangeFactory) throws AMQException; - - Exchange getExchange(String exchangeName); - - /** - * Unregister an exchange - * @param exchange name of the exchange to delete - * @param ifUnused if true, do NOT delete the exchange if it is in use (has queues bound to it) - * @throws ExchangeInUseException when the exchange cannot be deleted because it is in use - * @throws AMQException - */ - void unregisterExchange(String exchange, boolean ifUnused) throws ExchangeInUseException, AMQException; - - void clearAndUnregisterMbeans(); - - Exchange getExchange(UUID exchangeId); - - Collection<Exchange> getExchanges(); - - void addRegistryChangeListener(RegistryChangeListener listener); - - /** - * Validates the name of user custom exchange. - * <p> - * Return true if the exchange name is reserved and false otherwise. - */ - boolean isReservedExchangeName(String name); - - interface RegistryChangeListener - { - void exchangeRegistered(Exchange exchange); - void exchangeUnregistered(Exchange exchange); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java deleted file mode 100644 index cd830d69a9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicReference; -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQInvalidArgumentException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.filter.MessageFilter; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.BaseQueue; - -import java.util.ArrayList; -import java.util.concurrent.ConcurrentHashMap; - -public class FanoutExchange extends AbstractExchange -{ - private static final Logger _logger = Logger.getLogger(FanoutExchange.class); - - private static final Integer ONE = Integer.valueOf(1); - - /** - * Maps from queue name to queue instances - */ - private final Map<AMQQueue,Integer> _queues = new HashMap<AMQQueue,Integer>(); - private final CopyOnWriteArrayList<AMQQueue> _unfilteredQueues = new CopyOnWriteArrayList<AMQQueue>(); - private final CopyOnWriteArrayList<AMQQueue> _filteredQueues = new CopyOnWriteArrayList<AMQQueue>(); - - private final AtomicReference<Map<AMQQueue,Map<Binding, MessageFilter>>> _filteredBindings = - new AtomicReference<Map<AMQQueue,Map<Binding, MessageFilter>>>(); - { - Map<AMQQueue,Map<Binding, MessageFilter>> emptyMap = Collections.emptyMap(); - _filteredBindings.set(emptyMap); - } - - - - public static final ExchangeType<FanoutExchange> TYPE = new FanoutExchangeType(); - - public FanoutExchange() - { - super(TYPE); - } - - public ArrayList<BaseQueue> doRoute(InboundMessage payload) - { - - for(Binding b : getBindings()) - { - b.incrementMatches(); - } - - final ArrayList<BaseQueue> result = new ArrayList<BaseQueue>(_unfilteredQueues); - - - final Map<AMQQueue, Map<Binding, MessageFilter>> filteredBindings = _filteredBindings.get(); - if(!_filteredQueues.isEmpty()) - { - for(AMQQueue q : _filteredQueues) - { - final Map<Binding, MessageFilter> bindingMessageFilterMap = filteredBindings.get(q); - if(!(bindingMessageFilterMap == null || result.contains(q))) - { - for(MessageFilter filter : bindingMessageFilterMap.values()) - { - if(filter.matches(payload)) - { - result.add(q); - break; - } - } - } - } - - } - - - if (_logger.isDebugEnabled()) - { - _logger.debug("Publishing message to queue " + result); - } - - return result; - - } - - - protected synchronized void onBind(final Binding binding) - { - AMQQueue queue = binding.getQueue(); - assert queue != null; - if(binding.getArguments() == null || binding.getArguments().isEmpty() || !FilterSupport.argumentsContainFilter(binding.getArguments())) - { - - Integer oldVal; - if(_queues.containsKey(queue)) - { - _queues.put(queue,_queues.get(queue)+1); - } - else - { - _queues.put(queue, ONE); - _unfilteredQueues.add(queue); - // No longer any reason to check filters for this queue - _filteredQueues.remove(queue); - } - - } - else - { - try - { - - HashMap<AMQQueue,Map<Binding, MessageFilter>> filteredBindings = - new HashMap<AMQQueue,Map<Binding, MessageFilter>>(_filteredBindings.get()); - - Map<Binding, MessageFilter> bindingsForQueue = filteredBindings.remove(binding.getQueue()); - final - MessageFilter messageFilter = - FilterSupport.createMessageFilter(binding.getArguments(), binding.getQueue()); - - if(bindingsForQueue != null) - { - bindingsForQueue = new HashMap<Binding,MessageFilter>(bindingsForQueue); - bindingsForQueue.put(binding, messageFilter); - } - else - { - bindingsForQueue = Collections.singletonMap(binding, messageFilter); - if(!_unfilteredQueues.contains(queue)) - { - _filteredQueues.add(queue); - } - } - - filteredBindings.put(binding.getQueue(), bindingsForQueue); - - _filteredBindings.set(filteredBindings); - - } - catch (AMQInvalidArgumentException e) - { - _logger.warn("Cannoy bind queue " + queue + " to exchange this " + this + " beacuse selector cannot be parsed.", e); - return; - } - } - if (_logger.isDebugEnabled()) - { - _logger.debug("Binding queue " + queue - + " with routing key " + binding.getBindingKey() + " to exchange " + this); - } - } - - protected synchronized void onUnbind(final Binding binding) - { - AMQQueue queue = binding.getQueue(); - if(binding.getArguments() == null || binding.getArguments().isEmpty() || !FilterSupport.argumentsContainFilter(binding.getArguments())) - { - Integer oldValue = _queues.remove(queue); - if(ONE.equals(oldValue)) - { - // should start checking filters for this queue - if(_filteredBindings.get().containsKey(queue)) - { - _filteredQueues.add(queue); - } - _unfilteredQueues.remove(queue); - } - else - { - _queues.put(queue,oldValue-1); - } - } - else // we are removing a binding with filters - { - HashMap<AMQQueue,Map<Binding, MessageFilter>> filteredBindings = - new HashMap<AMQQueue,Map<Binding, MessageFilter>>(_filteredBindings.get()); - - Map<Binding,MessageFilter> bindingsForQueue = filteredBindings.remove(binding.getQueue()); - if(bindingsForQueue.size()>1) - { - bindingsForQueue = new HashMap<Binding,MessageFilter>(bindingsForQueue); - bindingsForQueue.remove(binding); - filteredBindings.put(binding.getQueue(),bindingsForQueue); - } - else - { - _filteredQueues.remove(queue); - } - _filteredBindings.set(filteredBindings); - - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java deleted file mode 100644 index ac864df02c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.UUID; - -import org.apache.qpid.AMQException; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public class FanoutExchangeType implements ExchangeType<FanoutExchange> -{ - @Override - public String getType() - { - return ExchangeDefaults.FANOUT_EXCHANGE_CLASS; - } - - public FanoutExchange newInstance(UUID id, VirtualHost host, String name, - boolean durable, boolean autoDelete) - throws AMQException - { - FanoutExchange exch = new FanoutExchange(); - exch.initialise(id, host, name, durable, autoDelete); - return exch; - } - - public String getDefaultExchangeName() - { - return ExchangeDefaults.FANOUT_EXCHANGE_NAME; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FilterSupport.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FilterSupport.java deleted file mode 100644 index e78516cf69..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FilterSupport.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.lang.ref.WeakReference; -import java.util.Collections; -import java.util.Map; -import java.util.WeakHashMap; -import org.apache.qpid.AMQInvalidArgumentException; -import org.apache.qpid.common.AMQPFilterTypes; -import org.apache.qpid.filter.SelectorParsingException; -import org.apache.qpid.filter.selector.ParseException; -import org.apache.qpid.filter.selector.TokenMgrError; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.filter.JMSSelectorFilter; -import org.apache.qpid.server.filter.MessageFilter; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.Filterable; - -public class FilterSupport -{ - private static final Map<String, WeakReference<JMSSelectorFilter>> _selectorCache = - Collections.synchronizedMap(new WeakHashMap<String, WeakReference<JMSSelectorFilter>>()); - - static MessageFilter createJMSSelectorFilter(Map<String, Object> args) throws AMQInvalidArgumentException - { - final String selectorString = (String) args.get(AMQPFilterTypes.JMS_SELECTOR.toString()); - return getMessageFilter(selectorString); - } - - - private static MessageFilter getMessageFilter(String selectorString) throws AMQInvalidArgumentException - { - WeakReference<JMSSelectorFilter> selectorRef = _selectorCache.get(selectorString); - JMSSelectorFilter selector = null; - - if(selectorRef == null || (selector = selectorRef.get())==null) - { - try - { - selector = new JMSSelectorFilter(selectorString); - } - catch (ParseException e) - { - throw new AMQInvalidArgumentException("Cannot parse JMS selector \"" + selectorString + "\"", e); - } - catch (SelectorParsingException e) - { - throw new AMQInvalidArgumentException("Cannot parse JMS selector \"" + selectorString + "\"", e); - } - catch (TokenMgrError e) - { - throw new AMQInvalidArgumentException("Cannot parse JMS selector \"" + selectorString + "\"", e); - } - _selectorCache.put(selectorString, new WeakReference<JMSSelectorFilter>(selector)); - } - return selector; - } - - public static boolean argumentsContainFilter(final Map<String, Object> args) - { - return argumentsContainNoLocal(args) || argumentsContainJMSSelector(args); - } - - - public static void removeFilters(final Map<String, Object> args) - { - args.remove(AMQPFilterTypes.JMS_SELECTOR.toString()); - args.remove(AMQPFilterTypes.NO_LOCAL.toString()); - } - - - - static boolean argumentsContainNoLocal(final Map<String, Object> args) - { - return args != null - && args.containsKey(AMQPFilterTypes.NO_LOCAL.toString()) - && Boolean.TRUE.equals(args.get(AMQPFilterTypes.NO_LOCAL.toString())); - } - - static boolean argumentsContainJMSSelector(final Map<String,Object> args) - { - return args != null && (args.get(AMQPFilterTypes.JMS_SELECTOR.toString()) instanceof String) - && ((String)args.get(AMQPFilterTypes.JMS_SELECTOR.toString())).trim().length() != 0; - } - - static MessageFilter createMessageFilter(final Map<String,Object> args, AMQQueue queue) throws AMQInvalidArgumentException - { - if(argumentsContainNoLocal(args)) - { - MessageFilter filter = new NoLocalFilter(queue); - - if(argumentsContainJMSSelector(args)) - { - filter = new CompoundFilter(filter, createJMSSelectorFilter(args)); - } - return filter; - } - else - { - return createJMSSelectorFilter(args); - } - } - - static final class NoLocalFilter implements MessageFilter - { - private final AMQQueue _queue; - - public NoLocalFilter(AMQQueue queue) - { - _queue = queue; - } - - public boolean matches(Filterable message) - { - InboundMessage inbound = (InboundMessage) message; - final AMQSessionModel exclusiveOwningSession = _queue.getExclusiveOwningSession(); - return exclusiveOwningSession == null || !exclusiveOwningSession.onSameConnection(inbound); - - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - - if (o == null || getClass() != o.getClass()) - { - return false; - } - - NoLocalFilter that = (NoLocalFilter) o; - - return _queue == null ? that._queue == null : _queue.equals(that._queue); - } - - @Override - public int hashCode() - { - return _queue != null ? _queue.hashCode() : 0; - } - } - - static final class CompoundFilter implements MessageFilter - { - private MessageFilter _noLocalFilter; - private MessageFilter _jmsSelectorFilter; - - public CompoundFilter(MessageFilter filter, MessageFilter jmsSelectorFilter) - { - _noLocalFilter = filter; - _jmsSelectorFilter = jmsSelectorFilter; - } - - public boolean matches(Filterable message) - { - return _noLocalFilter.matches(message) && _jmsSelectorFilter.matches(message); - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - - CompoundFilter that = (CompoundFilter) o; - - if (_jmsSelectorFilter != null ? !_jmsSelectorFilter.equals(that._jmsSelectorFilter) : that._jmsSelectorFilter != null) - { - return false; - } - if (_noLocalFilter != null ? !_noLocalFilter.equals(that._noLocalFilter) : that._noLocalFilter != null) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - int result = _noLocalFilter != null ? _noLocalFilter.hashCode() : 0; - result = 31 * result + (_jmsSelectorFilter != null ? _jmsSelectorFilter.hashCode() : 0); - return result; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersBinding.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersBinding.java deleted file mode 100644 index eb4a84a5b9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersBinding.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQInvalidArgumentException; -import org.apache.qpid.framing.AMQTypedValue; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.filter.MessageFilter; -import org.apache.qpid.server.message.AMQMessageHeader; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.queue.Filterable; - -/** - * Defines binding and matching based on a set of headers. - */ -class HeadersBinding -{ - private static final Logger _logger = Logger.getLogger(HeadersBinding.class); - - private final Map<String,Object> _mappings; - private final Binding _binding; - private final Set<String> required = new HashSet<String>(); - private final Map<String,Object> matches = new HashMap<String,Object>(); - private boolean matchAny; - private MessageFilter _filter; - - /** - * Creates a header binding for a set of mappings. Those mappings whose value is - * null or the empty string are assumed only to be required headers, with - * no constraint on the value. Those with a non-null value are assumed to - * define a required match of value. - * - * @param binding the binding to create a header binding using - */ - public HeadersBinding(Binding binding) - { - _binding = binding; - if(_binding !=null) - { - _mappings = _binding.getArguments(); - initMappings(); - } - else - { - _mappings = null; - } - } - - private void initMappings() - { - if(FilterSupport.argumentsContainFilter(_mappings)) - { - try - { - _filter = FilterSupport.createMessageFilter(_mappings,_binding.getQueue()); - } - catch (AMQInvalidArgumentException e) - { - _logger.warn("Invalid filter in binding queue '"+_binding.getQueue().getName() - +"' to exchange '"+_binding.getExchange().getName() - +"' with arguments: " + _binding.getArguments()); - _filter = new MessageFilter() - { - @Override - public boolean matches(Filterable message) - { - return false; - } - }; - } - } - for(Map.Entry<String, Object> entry : _mappings.entrySet()) - { - String propertyName = entry.getKey(); - Object value = entry.getValue(); - if (isSpecial(propertyName)) - { - processSpecial(propertyName, value); - } - else if (value == null || value.equals("")) - { - required.add(propertyName); - } - else - { - matches.put(propertyName,value); - } - } - } - - public Binding getBinding() - { - return _binding; - } - - /** - * Checks whether the supplied headers match the requirements of this binding - * @param headers the headers to check - * @return true if the headers define any required keys and match any required - * values - */ - public boolean matches(AMQMessageHeader headers) - { - if(headers == null) - { - return required.isEmpty() && matches.isEmpty(); - } - else - { - return matchAny ? or(headers) : and(headers); - } - } - - public boolean matches(InboundMessage message) - { - return matches(message.getMessageHeader()) && (_filter == null || _filter.matches(message)); - } - - private boolean and(AMQMessageHeader headers) - { - if(headers.containsHeaders(required)) - { - for(Map.Entry<String, Object> e : matches.entrySet()) - { - if(!e.getValue().equals(headers.getHeader(e.getKey()))) - { - return false; - } - } - return true; - } - else - { - return false; - } - } - - - private boolean or(final AMQMessageHeader headers) - { - if(required.isEmpty()) - { - return matches.isEmpty() || passesMatchesOr(headers); - } - else - { - if(!passesRequiredOr(headers)) - { - return !matches.isEmpty() && passesMatchesOr(headers); - } - else - { - return true; - } - - } - } - - private boolean passesMatchesOr(AMQMessageHeader headers) - { - for(Map.Entry<String,Object> entry : matches.entrySet()) - { - if(headers.containsHeader(entry.getKey()) - && ((entry.getValue() == null && headers.getHeader(entry.getKey()) == null) - || (entry.getValue().equals(headers.getHeader(entry.getKey()))))) - { - return true; - } - } - return false; - } - - private boolean passesRequiredOr(AMQMessageHeader headers) - { - for(String name : required) - { - if(headers.containsHeader(name)) - { - return true; - } - } - return false; - } - - private void processSpecial(String key, Object value) - { - if("X-match".equalsIgnoreCase(key)) - { - matchAny = isAny(value); - } - else - { - _logger.warn("Ignoring special header: " + key); - } - } - - private boolean isAny(Object value) - { - if(value instanceof String) - { - if("any".equalsIgnoreCase((String) value)) - { - return true; - } - if("all".equalsIgnoreCase((String) value)) - { - return false; - } - } - _logger.warn("Ignoring unrecognised match type: " + value); - return false;//default to all - } - - static boolean isSpecial(Object key) - { - return key instanceof String && isSpecial((String) key); - } - - static boolean isSpecial(String key) - { - return key.startsWith("X-") || key.startsWith("x-"); - } - - @Override - public boolean equals(final Object o) - { - if (this == o) - { - return true; - } - - if (o == null) - { - return false; - } - - if (!(o instanceof HeadersBinding)) - { - return false; - } - - final HeadersBinding hb = (HeadersBinding) o; - - if(_binding == null) - { - if(hb.getBinding() != null) - { - return false; - } - } - else if (!_binding.equals(hb.getBinding())) - { - return false; - } - - return true; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java deleted file mode 100644 index 41dd7e010c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import org.apache.log4j.Logger; - -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.message.AMQMessageHeader; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.BaseQueue; - -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CopyOnWriteArraySet; - -/** - * An exchange that binds queues based on a set of required headers and header values - * and routes messages to these queues by matching the headers of the message against - * those with which the queues were bound. - * <p/> - * <pre> - * The Headers Exchange - * - * Routes messages according to the value/presence of fields in the message header table. - * (Basic and JMS content has a content header field called "headers" that is a table of - * message header fields). - * - * class = "headers" - * routing key is not used - * - * Has the following binding arguments: - * - * the X-match field - if "all", does an AND match (used for GRM), if "any", does an OR match. - * other fields prefixed with "X-" are ignored (and generate a console warning message). - * a field with no value or empty value indicates a match on presence only. - * a field with a value indicates match on field presence and specific value. - * - * Standard instances: - * - * amq.match - pub/sub on field content/value - * </pre> - */ -public class HeadersExchange extends AbstractExchange -{ - - private static final Logger _logger = Logger.getLogger(HeadersExchange.class); - - private final ConcurrentHashMap<String, CopyOnWriteArraySet<Binding>> _bindingsByKey = - new ConcurrentHashMap<String, CopyOnWriteArraySet<Binding>>(); - - private final CopyOnWriteArrayList<HeadersBinding> _bindingHeaderMatchers = - new CopyOnWriteArrayList<HeadersBinding>(); - - - public static final ExchangeType<HeadersExchange> TYPE = new HeadersExchangeType(); - - public HeadersExchange() - { - super(TYPE); - } - - - public ArrayList<BaseQueue> doRoute(InboundMessage payload) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Exchange " + getName() + ": routing message with headers " + payload.getMessageHeader()); - } - - LinkedHashSet<BaseQueue> queues = new LinkedHashSet<BaseQueue>(); - - for (HeadersBinding hb : _bindingHeaderMatchers) - { - if (hb.matches(payload)) - { - Binding b = hb.getBinding(); - - b.incrementMatches(); - - if (_logger.isDebugEnabled()) - { - _logger.debug("Exchange " + getName() + ": delivering message with headers " + - payload.getMessageHeader() + " to " + b.getQueue().getName()); - } - queues.add(b.getQueue()); - } - } - - return new ArrayList<BaseQueue>(queues); - } - - protected void onBind(final Binding binding) - { - String bindingKey = binding.getBindingKey(); - AMQQueue queue = binding.getQueue(); - Map<String,Object> args = binding.getArguments(); - - assert queue != null; - assert bindingKey != null; - - CopyOnWriteArraySet<Binding> bindings = _bindingsByKey.get(bindingKey); - - if(bindings == null) - { - bindings = new CopyOnWriteArraySet<Binding>(); - CopyOnWriteArraySet<Binding> newBindings; - if((newBindings = _bindingsByKey.putIfAbsent(bindingKey, bindings)) != null) - { - bindings = newBindings; - } - } - - if(_logger.isDebugEnabled()) - { - _logger.debug("Exchange " + getName() + ": Binding " + queue.getName() + - " with binding key '" +bindingKey + "' and args: " + args); - } - - _bindingHeaderMatchers.add(new HeadersBinding(binding)); - bindings.add(binding); - - } - - protected void onUnbind(final Binding binding) - { - assert binding != null; - - CopyOnWriteArraySet<Binding> bindings = _bindingsByKey.get(binding.getBindingKey()); - if(bindings != null) - { - bindings.remove(binding); - } - - boolean removedBinding = _bindingHeaderMatchers.remove(new HeadersBinding(binding)); - if(_logger.isDebugEnabled()) - { - _logger.debug("Removing Binding: " + removedBinding); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java deleted file mode 100644 index 42d04f5a97..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.UUID; - -import org.apache.qpid.AMQException; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public class HeadersExchangeType implements ExchangeType<HeadersExchange> -{ - @Override - public String getType() - { - return ExchangeDefaults.HEADERS_EXCHANGE_CLASS; - } - - public HeadersExchange newInstance(UUID id, VirtualHost host, String name, boolean durable, - boolean autoDelete) throws AMQException - { - HeadersExchange exch = new HeadersExchange(); - - exch.initialise(id, host, name, durable, autoDelete); - return exch; - } - - public String getDefaultExchangeName() - { - - return ExchangeDefaults.HEADERS_EXCHANGE_NAME; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java deleted file mode 100644 index 6b8b84f5dd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQInvalidArgumentException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.exchange.topic.TopicExchangeResult; -import org.apache.qpid.server.exchange.topic.TopicMatcherResult; -import org.apache.qpid.server.exchange.topic.TopicNormalizer; -import org.apache.qpid.server.exchange.topic.TopicParser; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.BaseQueue; - -public class TopicExchange extends AbstractExchange -{ - public static final ExchangeType<TopicExchange> TYPE = new TopicExchangeType(); - - - private static final Logger _logger = Logger.getLogger(TopicExchange.class); - - private final TopicParser _parser = new TopicParser(); - - private final Map<String, TopicExchangeResult> _topicExchangeResults = - new ConcurrentHashMap<String, TopicExchangeResult>(); - - private final Map<Binding, Map<String,Object>> _bindings = new HashMap<Binding, Map<String,Object>>(); - - public TopicExchange() - { - super(TYPE); - } - - protected synchronized void registerQueue(final Binding binding) throws AMQInvalidArgumentException - { - final String bindingKey = binding.getBindingKey(); - AMQQueue queue = binding.getQueue(); - Map<String,Object> args = binding.getArguments(); - - assert queue != null; - assert bindingKey != null; - - _logger.debug("Registering queue " + queue.getName() + " with routing key " + bindingKey); - - - String routingKey = TopicNormalizer.normalize(bindingKey); - - if(_bindings.containsKey(binding)) - { - Map<String,Object> oldArgs = _bindings.get(binding); - TopicExchangeResult result = _topicExchangeResults.get(routingKey); - - if(FilterSupport.argumentsContainFilter(args)) - { - if(FilterSupport.argumentsContainFilter(oldArgs)) - { - result.replaceQueueFilter(queue, - FilterSupport.createMessageFilter(oldArgs, queue), - FilterSupport.createMessageFilter(args, queue)); - } - else - { - result.addFilteredQueue(queue, FilterSupport.createMessageFilter(args, queue)); - result.removeUnfilteredQueue(queue); - } - } - else - { - if(FilterSupport.argumentsContainFilter(oldArgs)) - { - result.addUnfilteredQueue(queue); - result.removeFilteredQueue(queue, FilterSupport.createMessageFilter(oldArgs, queue)); - } - else - { - // TODO - fix control flow - return; - } - } - - result.addBinding(binding); - - } - else - { - - TopicExchangeResult result = _topicExchangeResults.get(routingKey); - if(result == null) - { - result = new TopicExchangeResult(); - if(FilterSupport.argumentsContainFilter(args)) - { - result.addFilteredQueue(queue, FilterSupport.createMessageFilter(args, queue)); - } - else - { - result.addUnfilteredQueue(queue); - } - _parser.addBinding(routingKey, result); - _topicExchangeResults.put(routingKey,result); - } - else - { - if(FilterSupport.argumentsContainFilter(args)) - { - result.addFilteredQueue(queue, FilterSupport.createMessageFilter(args, queue)); - } - else - { - result.addUnfilteredQueue(queue); - } - } - - result.addBinding(binding); - _bindings.put(binding, args); - } - - } - - - public ArrayList<BaseQueue> doRoute(InboundMessage payload) - { - - final String routingKey = payload.getRoutingKey() == null - ? "" - : payload.getRoutingKey(); - - final Collection<AMQQueue> matchedQueues = getMatchedQueues(payload, routingKey); - - ArrayList<BaseQueue> queues; - - if(matchedQueues.getClass() == ArrayList.class) - { - queues = (ArrayList) matchedQueues; - } - else - { - queues = new ArrayList<BaseQueue>(); - queues.addAll(matchedQueues); - } - - if(queues == null || queues.isEmpty()) - { - _logger.info("Message routing key: " + payload.getRoutingKey() + " No routes."); - } - - return queues; - - } - - private boolean deregisterQueue(final Binding binding) - { - if(_bindings.containsKey(binding)) - { - Map<String,Object> bindingArgs = _bindings.remove(binding); - String bindingKey = TopicNormalizer.normalize(binding.getBindingKey()); - TopicExchangeResult result = _topicExchangeResults.get(bindingKey); - - result.removeBinding(binding); - - if(FilterSupport.argumentsContainFilter(bindingArgs)) - { - try - { - result.removeFilteredQueue(binding.getQueue(), FilterSupport.createMessageFilter(bindingArgs, - binding.getQueue())); - } - catch (AMQInvalidArgumentException e) - { - return false; - } - } - else - { - result.removeUnfilteredQueue(binding.getQueue()); - } - return true; - } - else - { - return false; - } - } - - private Collection<AMQQueue> getMatchedQueues(InboundMessage message, String routingKey) - { - - Collection<TopicMatcherResult> results = _parser.parse(routingKey); - switch(results.size()) - { - case 0: - return Collections.EMPTY_SET; - case 1: - TopicMatcherResult[] resultQueues = new TopicMatcherResult[1]; - results.toArray(resultQueues); - return ((TopicExchangeResult)resultQueues[0]).processMessage(message, null); - default: - Collection<AMQQueue> queues = new HashSet<AMQQueue>(); - for(TopicMatcherResult result : results) - { - TopicExchangeResult res = (TopicExchangeResult)result; - - for(Binding b : res.getBindings()) - { - b.incrementMatches(); - } - - queues = res.processMessage(message, queues); - } - return queues; - } - - - } - - protected void onBind(final Binding binding) - { - try - { - registerQueue(binding); - } - catch (AMQInvalidArgumentException e) - { - throw new RuntimeException(e); - } - } - - protected void onUnbind(final Binding binding) - { - deregisterQueue(binding); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java deleted file mode 100644 index 3bbae700be..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange; - -import java.util.UUID; - -import org.apache.qpid.AMQException; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public class TopicExchangeType implements ExchangeType<TopicExchange> -{ - @Override - public String getType() - { - return ExchangeDefaults.TOPIC_EXCHANGE_CLASS; - } - - public TopicExchange newInstance(UUID id, VirtualHost host, - String name, - boolean durable, - boolean autoDelete) throws AMQException - { - TopicExchange exch = new TopicExchange(); - exch.initialise(id, host, name, durable, autoDelete); - return exch; - } - - public String getDefaultExchangeName() - { - return ExchangeDefaults.TOPIC_EXCHANGE_NAME; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicExchangeResult.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicExchangeResult.java deleted file mode 100644 index 44d5f7f1d0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicExchangeResult.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange.topic; - -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.filter.MessageFilter; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.queue.AMQQueue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; - -public final class TopicExchangeResult implements TopicMatcherResult -{ - private final List<Binding> _bindings = new CopyOnWriteArrayList<Binding>(); - private final Map<AMQQueue, Integer> _unfilteredQueues = new ConcurrentHashMap<AMQQueue, Integer>(); - private final ConcurrentHashMap<AMQQueue, Map<MessageFilter,Integer>> _filteredQueues = new ConcurrentHashMap<AMQQueue, Map<MessageFilter, Integer>>(); - private volatile ArrayList<AMQQueue> _unfilteredQueueList = new ArrayList<AMQQueue>(0); - - public void addUnfilteredQueue(AMQQueue queue) - { - Integer instances = _unfilteredQueues.get(queue); - if(instances == null) - { - _unfilteredQueues.put(queue, 1); - ArrayList<AMQQueue> newList = new ArrayList<AMQQueue>(_unfilteredQueueList); - newList.add(queue); - _unfilteredQueueList = newList; - } - else - { - _unfilteredQueues.put(queue, instances + 1); - } - } - - public void removeUnfilteredQueue(AMQQueue queue) - { - Integer instances = _unfilteredQueues.get(queue); - if(instances == 1) - { - _unfilteredQueues.remove(queue); - ArrayList<AMQQueue> newList = new ArrayList<AMQQueue>(_unfilteredQueueList); - newList.remove(queue); - _unfilteredQueueList = newList; - - } - else - { - _unfilteredQueues.put(queue,instances - 1); - } - - } - - public Collection<AMQQueue> getUnfilteredQueues() - { - return _unfilteredQueues.keySet(); - } - - public void addBinding(Binding binding) - { - _bindings.add(binding); - } - - public void removeBinding(Binding binding) - { - _bindings.remove(binding); - } - - public List<Binding> getBindings() - { - return new ArrayList<Binding>(_bindings); - } - - public void addFilteredQueue(AMQQueue queue, MessageFilter filter) - { - Map<MessageFilter,Integer> filters = _filteredQueues.get(queue); - if(filters == null) - { - filters = new ConcurrentHashMap<MessageFilter,Integer>(); - _filteredQueues.put(queue, filters); - } - Integer instances = filters.get(filter); - if(instances == null) - { - filters.put(filter,1); - } - else - { - filters.put(filter, instances + 1); - } - - } - - public void removeFilteredQueue(AMQQueue queue, MessageFilter filter) - { - Map<MessageFilter,Integer> filters = _filteredQueues.get(queue); - if(filters != null) - { - Integer instances = filters.get(filter); - if(instances != null) - { - if(instances == 1) - { - filters.remove(filter); - if(filters.isEmpty()) - { - _filteredQueues.remove(queue); - } - } - else - { - filters.put(filter, instances - 1); - } - } - - } - - } - - public void replaceQueueFilter(AMQQueue queue, - MessageFilter oldFilter, - MessageFilter newFilter) - { - Map<MessageFilter,Integer> filters = _filteredQueues.get(queue); - Map<MessageFilter,Integer> newFilters = new ConcurrentHashMap<MessageFilter,Integer>(filters); - Integer oldFilterInstances = filters.get(oldFilter); - if(oldFilterInstances == 1) - { - newFilters.remove(oldFilter); - } - else - { - newFilters.put(oldFilter, oldFilterInstances-1); - } - Integer newFilterInstances = filters.get(newFilter); - if(newFilterInstances == null) - { - newFilters.put(newFilter, 1); - } - else - { - newFilters.put(newFilter, newFilterInstances+1); - } - _filteredQueues.put(queue,newFilters); - } - - public Collection<AMQQueue> processMessage(InboundMessage msg, Collection<AMQQueue> queues) - { - if(queues == null) - { - if(_filteredQueues.isEmpty()) - { - return _unfilteredQueueList; - } - else - { - queues = new HashSet<AMQQueue>(); - } - } - else if(!(queues instanceof Set)) - { - queues = new HashSet<AMQQueue>(queues); - } - - queues.addAll(_unfilteredQueues.keySet()); - if(!_filteredQueues.isEmpty()) - { - for(Map.Entry<AMQQueue, Map<MessageFilter, Integer>> entry : _filteredQueues.entrySet()) - { - if(!queues.contains(entry.getKey())) - { - for(MessageFilter filter : entry.getValue().keySet()) - { - if(filter.matches(msg)) - { - queues.add(entry.getKey()); - } - } - } - } - } - return queues; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicMatcherDFAState.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicMatcherDFAState.java deleted file mode 100644 index 85338c0760..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicMatcherDFAState.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange.topic; - -import java.util.Arrays; -import java.util.Iterator; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicInteger; - -public class TopicMatcherDFAState -{ - private static final AtomicInteger stateId = new AtomicInteger(); - - private final int _id = stateId.incrementAndGet(); - - private final Collection<TopicMatcherResult> _results; - private final Map<TopicWord, TopicMatcherDFAState> _nextStateMap; - private static final String TOPIC_DELIMITTER = "\\."; - - - public TopicMatcherDFAState(Map<TopicWord, TopicMatcherDFAState> nextStateMap, - Collection<TopicMatcherResult> results ) - { - _nextStateMap = nextStateMap; - _results = results; - } - - - public TopicMatcherDFAState nextState(TopicWord word) - { - final TopicMatcherDFAState nextState = _nextStateMap.get(word); - return nextState == null ? _nextStateMap.get(TopicWord.ANY_WORD) : nextState; - } - - public Collection<TopicMatcherResult> terminate() - { - return _results; - } - - - public Collection<TopicMatcherResult> parse(TopicWordDictionary dictionary, String routingKey) - { - return parse(dictionary, Arrays.asList(routingKey.split(TOPIC_DELIMITTER)).iterator()); - } - - private Collection<TopicMatcherResult> parse(final TopicWordDictionary dictionary, - final Iterator<String> tokens) - { - if(!tokens.hasNext()) - { - return _results; - } - TopicWord word = dictionary.getWord(tokens.next()); - TopicMatcherDFAState nextState = _nextStateMap.get(word); - if(nextState == null && word != TopicWord.ANY_WORD) - { - nextState = _nextStateMap.get(TopicWord.ANY_WORD); - } - if(nextState == null) - { - return Collections.EMPTY_LIST; - } - // Shortcut if we are at a looping terminal state - if((nextState == this) && (_nextStateMap.size() == 1) && _nextStateMap.containsKey(TopicWord.ANY_WORD)) - { - return _results; - } - - return nextState.parse(dictionary, tokens); - - } - - - public TopicMatcherDFAState mergeStateMachines(TopicMatcherDFAState otherStateMachine) - { - Map<Set<TopicMatcherDFAState>, TopicMatcherDFAState> newStateMap= new HashMap<Set<TopicMatcherDFAState>, TopicMatcherDFAState>(); - - Collection<TopicMatcherResult> results; - - if(_results.isEmpty()) - { - results = otherStateMachine._results; - } - else if(otherStateMachine._results.isEmpty()) - { - results = _results; - } - else - { - results = new HashSet<TopicMatcherResult>(_results); - results.addAll(otherStateMachine._results); - } - - - final Map<TopicWord, TopicMatcherDFAState> newNextStateMap = new HashMap<TopicWord, TopicMatcherDFAState>(); - - TopicMatcherDFAState newState = new TopicMatcherDFAState(newNextStateMap, results); - - - Set<TopicMatcherDFAState> oldStates = new HashSet<TopicMatcherDFAState>(); - oldStates.add(this); - oldStates.add(otherStateMachine); - - newStateMap.put(oldStates, newState); - - mergeStateMachines(oldStates, newNextStateMap, newStateMap); - - return newState; - - } - - private static void mergeStateMachines( - final Set<TopicMatcherDFAState> oldStates, - final Map<TopicWord, TopicMatcherDFAState> newNextStateMap, - final Map<Set<TopicMatcherDFAState>, TopicMatcherDFAState> newStateMap) - { - Map<TopicWord, Set<TopicMatcherDFAState>> nfaMap = new HashMap<TopicWord, Set<TopicMatcherDFAState>>(); - - for(TopicMatcherDFAState state : oldStates) - { - Map<TopicWord, TopicMatcherDFAState> map = state._nextStateMap; - for(Map.Entry<TopicWord, TopicMatcherDFAState> entry : map.entrySet()) - { - Set<TopicMatcherDFAState> states = nfaMap.get(entry.getKey()); - if(states == null) - { - states = new HashSet<TopicMatcherDFAState>(); - nfaMap.put(entry.getKey(), states); - } - states.add(entry.getValue()); - } - } - - Set<TopicMatcherDFAState> anyWordStates = nfaMap.get(TopicWord.ANY_WORD); - - for(Map.Entry<TopicWord, Set<TopicMatcherDFAState>> transition : nfaMap.entrySet()) - { - Set<TopicMatcherDFAState> destinations = transition.getValue(); - - if(anyWordStates != null) - { - destinations.addAll(anyWordStates); - } - - TopicMatcherDFAState nextState = newStateMap.get(destinations); - if(nextState == null) - { - - if(destinations.size() == 1) - { - nextState = destinations.iterator().next(); - newStateMap.put(destinations, nextState); - } - else - { - Collection<TopicMatcherResult> results; - - Set<Collection<TopicMatcherResult>> resultSets = new HashSet<Collection<TopicMatcherResult>>(); - for(TopicMatcherDFAState destination : destinations) - { - resultSets.add(destination._results); - } - resultSets.remove(Collections.EMPTY_SET); - if(resultSets.size() == 0) - { - results = Collections.EMPTY_SET; - } - else if(resultSets.size() == 1) - { - results = resultSets.iterator().next(); - } - else - { - results = new HashSet<TopicMatcherResult>(); - for(Collection<TopicMatcherResult> oldResult : resultSets) - { - results.addAll(oldResult); - } - } - - final Map<TopicWord, TopicMatcherDFAState> nextStateMap = new HashMap<TopicWord, TopicMatcherDFAState>(); - - nextState = new TopicMatcherDFAState(nextStateMap, results); - newStateMap.put(destinations, nextState); - - mergeStateMachines( - destinations, - nextStateMap, - newStateMap); - - - } - - - } - newNextStateMap.put(transition.getKey(),nextState); - } - - // Remove redundant transitions where defined tokenWord has same action as ANY_WORD - TopicMatcherDFAState anyWordState = newNextStateMap.get(TopicWord.ANY_WORD); - if(anyWordState != null) - { - List<TopicWord> removeList = new ArrayList<TopicWord>(); - for(Map.Entry<TopicWord,TopicMatcherDFAState> entry : newNextStateMap.entrySet()) - { - if(entry.getValue() == anyWordState && entry.getKey() != TopicWord.ANY_WORD) - { - removeList.add(entry.getKey()); - } - } - for(TopicWord removeKey : removeList) - { - newNextStateMap.remove(removeKey); - } - } - - - - } - - - public String toString() - { - StringBuilder transitions = new StringBuilder(); - for(Map.Entry<TopicWord, TopicMatcherDFAState> entry : _nextStateMap.entrySet()) - { - transitions.append("[ "); - transitions.append(entry.getKey()); - transitions.append("\t ->\t "); - transitions.append(entry.getValue().getId()); - transitions.append(" ]\n"); - } - - - return "[ State " + getId() + " ]\n" + transitions + "\n"; - - } - - public String reachableStates() - { - StringBuilder result = new StringBuilder("Start state: " + getId() + "\n"); - - SortedSet<TopicMatcherDFAState> reachableStates = - new TreeSet<TopicMatcherDFAState>(new Comparator<TopicMatcherDFAState>() - { - public int compare(final TopicMatcherDFAState o1, final TopicMatcherDFAState o2) - { - return o1.getId() - o2.getId(); - } - }); - reachableStates.add(this); - - int count; - - do - { - count = reachableStates.size(); - Collection<TopicMatcherDFAState> originalStates = new ArrayList<TopicMatcherDFAState>(reachableStates); - for(TopicMatcherDFAState state : originalStates) - { - reachableStates.addAll(state._nextStateMap.values()); - } - } - while(reachableStates.size() != count); - - - - for(TopicMatcherDFAState state : reachableStates) - { - result.append(state.toString()); - } - - return result.toString(); - } - - - int getId() - { - return _id; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicMatcherResult.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicMatcherResult.java deleted file mode 100644 index 6084b18b31..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicMatcherResult.java +++ /dev/null @@ -1,25 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.exchange.topic; - -public interface TopicMatcherResult -{ -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicNormalizer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicNormalizer.java deleted file mode 100644 index e45d6a539d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicNormalizer.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange.topic; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.ArrayList; -import java.util.List; - -public class TopicNormalizer -{ - - private static final String STAR_TOKEN = "*"; - private static final String HASH_TOKEN = "#"; - private static final String SEPARATOR = "."; - - - private TopicNormalizer() - { - } - - public static String normalize(String routingKey) - { - if(routingKey == null) - { - return ""; - } - else if(!(routingKey.contains(HASH_TOKEN) || !routingKey.contains(STAR_TOKEN))) - { - return routingKey; - } - else - { - List<String> subscriptionList = new ArrayList<String>(Arrays.asList(routingKey.split("\\."))); - - int size = subscriptionList.size(); - - for (int index = 0; index < size; index++) - { - // if there are more levels - if ((index + 1) < size) - { - if (subscriptionList.get(index).equals(HASH_TOKEN)) - { - if (subscriptionList.get(index + 1).equals(HASH_TOKEN)) - { - // we don't need #.# delete this one - subscriptionList.remove(index); - size--; - // redo this normalisation - index--; - } - - if (subscriptionList.get(index + 1).equals(STAR_TOKEN)) - { - // we don't want #.* swap to *.# - // remove it and put it in at index + 1 - subscriptionList.add(index + 1, subscriptionList.remove(index)); - } - } - } // if we have more levels - } - - Iterator<String> iter = subscriptionList.iterator(); - StringBuilder builder = new StringBuilder(iter.next()); - while(iter.hasNext()) - { - builder.append(SEPARATOR).append(iter.next()); - } - return builder.toString(); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicParser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicParser.java deleted file mode 100644 index 214ca23b49..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicParser.java +++ /dev/null @@ -1,456 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.exchange.topic; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; - -public class TopicParser -{ - private static final String TOPIC_DELIMITER = "\\."; - - private final TopicWordDictionary _dictionary = new TopicWordDictionary(); - private final AtomicReference<TopicMatcherDFAState> _stateMachine = new AtomicReference<TopicMatcherDFAState>(); - - private static class Position - { - private final TopicWord _word; - private final boolean _selfTransition; - private final int _position; - private final boolean _endState; - private boolean _followedByAnyLoop; - - - public Position(final int position, final TopicWord word, final boolean selfTransition, final boolean endState) - { - _position = position; - _word = word; - _selfTransition = selfTransition; - _endState = endState; - } - - - public TopicWord getWord() - { - return _word; - } - - public boolean isSelfTransition() - { - return _selfTransition; - } - - public int getPosition() - { - return _position; - } - - public boolean isEndState() - { - return _endState; - } - - public boolean isFollowedByAnyLoop() - { - return _followedByAnyLoop; - } - - public void setFollowedByAnyLoop(boolean followedByAnyLoop) - { - _followedByAnyLoop = followedByAnyLoop; - } - } - - private static final Position ERROR_POSITION = new Position(Integer.MAX_VALUE,null, true, false); - - private static class SimpleState - { - private Set<Position> _positions; - private Map<TopicWord, SimpleState> _nextState; - } - - - public void addBinding(String bindingKey, TopicMatcherResult result) - { - - TopicMatcherDFAState startingStateMachine; - TopicMatcherDFAState newStateMachine; - - do - { - startingStateMachine = _stateMachine.get(); - if(startingStateMachine == null) - { - newStateMachine = createStateMachine(bindingKey, result); - } - else - { - newStateMachine = startingStateMachine.mergeStateMachines(createStateMachine(bindingKey, result)); - } - - } - while(!_stateMachine.compareAndSet(startingStateMachine,newStateMachine)); - - } - - public Collection<TopicMatcherResult> parse(String routingKey) - { - TopicMatcherDFAState stateMachine = _stateMachine.get(); - if(stateMachine == null) - { - return Collections.EMPTY_SET; - } - else - { - return stateMachine.parse(_dictionary,routingKey); - } - } - - - TopicMatcherDFAState createStateMachine(String bindingKey, TopicMatcherResult result) - { - List<TopicWord> wordList = createTopicWordList(bindingKey); - int wildCards = 0; - for(TopicWord word : wordList) - { - if(word == TopicWord.WILDCARD_WORD) - { - wildCards++; - } - } - if(wildCards == 0) - { - TopicMatcherDFAState[] states = new TopicMatcherDFAState[wordList.size()+1]; - states[states.length-1] = new TopicMatcherDFAState(Collections.EMPTY_MAP, Collections.singleton(result)); - for(int i = states.length-2; i >= 0; i--) - { - states[i] = new TopicMatcherDFAState(Collections.singletonMap(wordList.get(i),states[i+1]),Collections.EMPTY_SET); - - } - return states[0]; - } - else if(wildCards == wordList.size()) - { - Map<TopicWord,TopicMatcherDFAState> stateMap = new HashMap<TopicWord,TopicMatcherDFAState>(); - TopicMatcherDFAState state = new TopicMatcherDFAState(stateMap, Collections.singleton(result)); - stateMap.put(TopicWord.ANY_WORD, state); - return state; - } - - - int positionCount = wordList.size() - wildCards; - - Position[] positions = new Position[positionCount+1]; - - int lastWord; - - if(wordList.get(wordList.size()-1)== TopicWord.WILDCARD_WORD) - { - lastWord = wordList.size()-1; - positions[positionCount] = new Position(positionCount, TopicWord.ANY_WORD, true, true); - } - else - { - lastWord = wordList.size(); - positions[positionCount] = new Position(positionCount, TopicWord.ANY_WORD, false, true); - } - - - int pos = 0; - int wordPos = 0; - - - while(wordPos < lastWord) - { - TopicWord word = wordList.get(wordPos++); - - if(word == TopicWord.WILDCARD_WORD) - { - int nextWordPos = wordPos++; - word = wordList.get(nextWordPos); - - positions[pos] = new Position(pos++,word,true,false); - } - else - { - positions[pos] = new Position(pos++,word,false,false); - } - - } - - - for(int p = 0; p<positionCount; p++) - { - boolean followedByWildcards = true; - - int n = p; - while(followedByWildcards && n<(positionCount+1)) - { - - if(positions[n].isSelfTransition()) - { - break; - } - else if(positions[n].getWord() !=TopicWord.ANY_WORD) - { - followedByWildcards = false; - } - n++; - } - - - positions[p].setFollowedByAnyLoop(followedByWildcards && (n!= positionCount+1)); - } - - - // from each position you transition to a set of other positions. - // we approach this by examining steps of increasing length - so we - // look how far we can go from the start position in 1 word, 2 words, etc... - - Map<Set<Position>,SimpleState> stateMap = new HashMap<Set<Position>,SimpleState>(); - - - SimpleState state = new SimpleState(); - state._positions = Collections.singleton( positions[0] ); - stateMap.put(state._positions, state); - - calculateNextStates(state, stateMap, positions); - - SimpleState[] simpleStates = stateMap.values().toArray(new SimpleState[stateMap.size()]); - HashMap<TopicWord, TopicMatcherDFAState>[] dfaStateMaps = new HashMap[simpleStates.length]; - Map<SimpleState, TopicMatcherDFAState> simple2DFAMap = new HashMap<SimpleState, TopicMatcherDFAState>(); - - for(int i = 0; i < simpleStates.length; i++) - { - - Collection<TopicMatcherResult> results; - boolean endState = false; - - for(Position p : simpleStates[i]._positions) - { - if(p.isEndState()) - { - endState = true; - break; - } - } - - if(endState) - { - results = Collections.singleton(result); - } - else - { - results = Collections.EMPTY_SET; - } - - dfaStateMaps[i] = new HashMap<TopicWord, TopicMatcherDFAState>(); - simple2DFAMap.put(simpleStates[i], new TopicMatcherDFAState(dfaStateMaps[i],results)); - - } - for(int i = 0; i < simpleStates.length; i++) - { - SimpleState simpleState = simpleStates[i]; - - Map<TopicWord, SimpleState> nextSimpleStateMap = simpleState._nextState; - for(Map.Entry<TopicWord, SimpleState> stateMapEntry : nextSimpleStateMap.entrySet()) - { - dfaStateMaps[i].put(stateMapEntry.getKey(), simple2DFAMap.get(stateMapEntry.getValue())); - } - - } - - return simple2DFAMap.get(state); - - } - - - - private void calculateNextStates(final SimpleState state, - final Map<Set<Position>, SimpleState> stateMap, - final Position[] positions) - { - Map<TopicWord, Set<Position>> transitions = new HashMap<TopicWord,Set<Position>>(); - - for(Position pos : state._positions) - { - if(pos.isSelfTransition()) - { - Set<Position> dest = transitions.get(TopicWord.ANY_WORD); - if(dest == null) - { - dest = new HashSet<Position>(); - transitions.put(TopicWord.ANY_WORD,dest); - } - dest.add(pos); - } - - final int nextPos = pos.getPosition() + 1; - Position nextPosition = nextPos == positions.length ? ERROR_POSITION : positions[nextPos]; - - Set<Position> dest = transitions.get(pos.getWord()); - if(dest == null) - { - dest = new HashSet<Position>(); - transitions.put(pos.getWord(),dest); - } - dest.add(nextPosition); - - } - - Set<Position> anyWordTransitions = transitions.get(TopicWord.ANY_WORD); - if(anyWordTransitions != null) - { - for(Set<Position> dest : transitions.values()) - { - dest.addAll(anyWordTransitions); - } - } - - state._nextState = new HashMap<TopicWord, SimpleState>(); - - for(Map.Entry<TopicWord,Set<Position>> dest : transitions.entrySet()) - { - - if(dest.getValue().size()>1) - { - dest.getValue().remove(ERROR_POSITION); - } - Position loopingTerminal = null; - for(Position destPos : dest.getValue()) - { - if(destPos.isSelfTransition() && destPos.isEndState()) - { - loopingTerminal = destPos; - break; - } - } - - if(loopingTerminal!=null) - { - dest.setValue(Collections.singleton(loopingTerminal)); - } - else - { - Position anyLoop = null; - for(Position destPos : dest.getValue()) - { - if(destPos.isFollowedByAnyLoop()) - { - if(anyLoop == null || anyLoop.getPosition() < destPos.getPosition()) - { - anyLoop = destPos; - } - } - } - if(anyLoop != null) - { - Collection<Position> removals = new ArrayList<Position>(); - for(Position destPos : dest.getValue()) - { - if(destPos.getPosition() < anyLoop.getPosition()) - { - removals.add(destPos); - } - } - dest.getValue().removeAll(removals); - } - } - - SimpleState stateForEntry = stateMap.get(dest.getValue()); - if(stateForEntry == null) - { - stateForEntry = new SimpleState(); - stateForEntry._positions = dest.getValue(); - stateMap.put(dest.getValue(),stateForEntry); - calculateNextStates(stateForEntry, - stateMap, - positions); - } - state._nextState.put(dest.getKey(),stateForEntry); - - - - } - - // remove redundant transitions - SimpleState anyWordState = state._nextState.get(TopicWord.ANY_WORD); - if(anyWordState != null) - { - List<TopicWord> removeList = new ArrayList<TopicWord>(); - for(Map.Entry<TopicWord,SimpleState> entry : state._nextState.entrySet()) - { - if(entry.getValue() == anyWordState && entry.getKey() != TopicWord.ANY_WORD) - { - removeList.add(entry.getKey()); - } - } - for(TopicWord removeKey : removeList) - { - state._nextState.remove(removeKey); - } - } - - - } - - private List<TopicWord> createTopicWordList(final String bindingKey) - { - String[] tokens = bindingKey.split(TOPIC_DELIMITER); - TopicWord previousWord = null; - - List<TopicWord> wordList = new ArrayList<TopicWord>(); - - for(String token : tokens) - { - TopicWord nextWord = _dictionary.getOrCreateWord(token); - if(previousWord == TopicWord.WILDCARD_WORD) - { - - if(nextWord == TopicWord.WILDCARD_WORD) - { - // consecutive wildcards can be merged - // i.e. subsequent wildcards can be discarded - continue; - } - else if(nextWord == TopicWord.ANY_WORD) - { - // wildcard and anyword can be reordered to always put anyword first - wordList.set(wordList.size()-1,TopicWord.ANY_WORD); - nextWord = TopicWord.WILDCARD_WORD; - } - } - wordList.add(nextWord); - previousWord = nextWord; - - } - return wordList; - } - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicWord.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicWord.java deleted file mode 100644 index c905299733..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicWord.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.exchange.topic; - -public final class TopicWord -{ - public static final TopicWord ANY_WORD = new TopicWord("*"); - public static final TopicWord WILDCARD_WORD = new TopicWord("#"); - private String _word; - - public TopicWord(String s) - { - _word = s; - } - - public String toString() - { - return _word; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicWordDictionary.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicWordDictionary.java deleted file mode 100644 index 24c41ee7da..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/topic/TopicWordDictionary.java +++ /dev/null @@ -1,56 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.exchange.topic; - -import java.util.concurrent.ConcurrentHashMap; - -public class TopicWordDictionary -{ - private final ConcurrentHashMap<String,TopicWord> _dictionary = - new ConcurrentHashMap<String,TopicWord>(); - - public TopicWordDictionary() - { - _dictionary.put("*", TopicWord.ANY_WORD); - _dictionary.put("#", TopicWord.WILDCARD_WORD); - } - - public TopicWord getOrCreateWord(String name) - { - TopicWord word = _dictionary.putIfAbsent(name, new TopicWord(name)); - if(word == null) - { - word = _dictionary.get(name); - } - return word; - } - - - public TopicWord getWord(String name) - { - TopicWord word = _dictionary.get(name); - if(word == null) - { - word = TopicWord.ANY_WORD; - } - return word; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/FilterManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/FilterManager.java deleted file mode 100644 index b5e282038b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/FilterManager.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.filter; -// -// Based on like named file from r450141 of the Apache ActiveMQ project <http://www.activemq.org/site/home.html> -// - -import org.apache.qpid.server.queue.Filterable; - -public interface FilterManager -{ - void add(MessageFilter filter); - - void remove(MessageFilter filter); - - boolean allAllow(Filterable msg); - - boolean hasFilters(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/FilterManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/FilterManagerFactory.java deleted file mode 100644 index 07049a6c97..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/FilterManagerFactory.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.filter; - -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQInvalidArgumentException; -import org.apache.qpid.common.AMQPFilterTypes; -import org.apache.qpid.filter.SelectorParsingException; -import org.apache.qpid.filter.selector.ParseException; -import org.apache.qpid.filter.selector.TokenMgrError; -import org.apache.qpid.framing.FieldTable; - -import java.util.Map; - - -public class FilterManagerFactory -{ - - private final static Logger _logger = Logger.getLogger(FilterManagerFactory.class); - - private FilterManagerFactory() - { - } - - //fixme move to a common class so it can be refered to from client code. - - public static FilterManager createManager(Map<String,Object> filters) throws AMQException - { - FilterManager manager = null; - - if (filters != null) - { - - if(filters.containsKey(AMQPFilterTypes.JMS_SELECTOR.toString())) - { - Object selector = filters.get(AMQPFilterTypes.JMS_SELECTOR.toString()); - - if (selector instanceof String && !selector.equals("")) - { - manager = new SimpleFilterManager(); - try - { - manager.add(new JMSSelectorFilter((String)selector)); - } - catch (ParseException e) - { - throw new AMQInvalidArgumentException("Cannot parse JMS selector \"" + selector + "\"", e); - } - catch (SelectorParsingException e) - { - throw new AMQInvalidArgumentException("Cannot parse JMS selector \"" + selector + "\"", e); - } - catch (TokenMgrError e) - { - throw new AMQInvalidArgumentException("Cannot parse JMS selector \"" + selector + "\"", e); - } - } - - } - - - } - else - { - _logger.debug("No Filters found."); - } - - - return manager; - - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/JMSSelectorFilter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/JMSSelectorFilter.java deleted file mode 100644 index 3d0d9a0f31..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/JMSSelectorFilter.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.filter; - -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.apache.log4j.Logger; -import org.apache.qpid.filter.BooleanExpression; -import org.apache.qpid.filter.FilterableMessage; -import org.apache.qpid.filter.SelectorParsingException; -import org.apache.qpid.filter.selector.ParseException; -import org.apache.qpid.filter.selector.SelectorParser; -import org.apache.qpid.filter.selector.TokenMgrError; -import org.apache.qpid.server.queue.Filterable; - - -public class JMSSelectorFilter implements MessageFilter -{ - private final static Logger _logger = org.apache.log4j.Logger.getLogger(JMSSelectorFilter.class); - - private String _selector; - private BooleanExpression _matcher; - - public JMSSelectorFilter(String selector) throws ParseException, TokenMgrError, SelectorParsingException - { - _selector = selector; - _matcher = new SelectorParser().parse(selector); - } - - public boolean matches(Filterable message) - { - - boolean match = _matcher.matches(wrap(message)); - if(_logger.isDebugEnabled()) - { - _logger.debug(message + " match(" + match + ") selector(" + System.identityHashCode(_selector) + "):" + _selector); - } - return match; - } - - private FilterableMessage wrap(final Filterable message) - { - return new FilterableMessage() - { - public boolean isPersistent() - { - return message.isPersistent(); - } - - public boolean isRedelivered() - { - return message.isRedelivered(); - } - - public Object getHeader(String name) - { - return message.getMessageHeader().getHeader(name); - } - - public String getReplyTo() - { - return message.getMessageHeader().getReplyTo(); - } - - public String getType() - { - return message.getMessageHeader().getType(); - } - - public byte getPriority() - { - return message.getMessageHeader().getPriority(); - } - - public String getMessageId() - { - return message.getMessageHeader().getMessageId(); - } - - public long getTimestamp() - { - return message.getMessageHeader().getTimestamp(); - } - - public String getCorrelationId() - { - return message.getMessageHeader().getCorrelationId(); - } - - public long getExpiration() - { - return message.getMessageHeader().getExpiration(); - } - }; - } - - public String getSelector() - { - return _selector; - } - - @Override - public String toString() - { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) - .append("selector", _selector) - .toString(); - } - - @Override - public int hashCode() - { - return new HashCodeBuilder().append(_selector).toHashCode(); - } - - @Override - public boolean equals(Object obj) - { - if (obj == null) - { - return false; - } - if (obj == this) - { - return true; - } - if (obj.getClass() != getClass()) - { - return false; - } - JMSSelectorFilter rhs = (JMSSelectorFilter) obj; - return new EqualsBuilder().append(_selector, rhs._selector).isEquals(); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/MessageFilter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/MessageFilter.java deleted file mode 100644 index f5416af09a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/MessageFilter.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.filter; - -import org.apache.qpid.server.queue.Filterable; - -public interface MessageFilter -{ - boolean matches(Filterable message); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/NoConsumerFilter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/NoConsumerFilter.java deleted file mode 100644 index d3e097d22c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/NoConsumerFilter.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.filter; - -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.queue.Filterable; - -public class NoConsumerFilter implements MessageFilter -{ - private final static Logger _logger = org.apache.log4j.Logger.getLogger(NoConsumerFilter.class); - - - public NoConsumerFilter() throws AMQException - { - _logger.info("Created NoConsumerFilter"); - } - - public boolean matches(Filterable message) - { - return true; - } - - @Override - public String toString() - { - return "NoConsumer"; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/SimpleFilterManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/SimpleFilterManager.java deleted file mode 100644 index 6c158de8b5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/SimpleFilterManager.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.filter; - -import org.apache.log4j.Logger; - -import org.apache.qpid.server.queue.Filterable; - -import java.util.concurrent.ConcurrentLinkedQueue; - -public class SimpleFilterManager implements FilterManager -{ - private final Logger _logger = Logger.getLogger(SimpleFilterManager.class); - - private final ConcurrentLinkedQueue<MessageFilter> _filters; - private String _toString = ""; - - public SimpleFilterManager() - { - _logger.debug("Creating SimpleFilterManager"); - _filters = new ConcurrentLinkedQueue<MessageFilter>(); - } - - public SimpleFilterManager(JMSSelectorFilter messageFilter) - { - this(); - add(messageFilter); - } - - public void add(MessageFilter filter) - { - _filters.add(filter); - updateStringValue(); - } - - public void remove(MessageFilter filter) - { - _filters.remove(filter); - updateStringValue(); - } - - public boolean allAllow(Filterable msg) - { - for (MessageFilter filter : _filters) - { - if (!filter.matches(msg)) - { - return false; - } - } - return true; - } - - public boolean hasFilters() - { - return !_filters.isEmpty(); - } - - - @Override - public String toString() - { - return _toString; - } - - private void updateStringValue() - { - StringBuilder toString = new StringBuilder(); - for (MessageFilter filter : _filters) - { - toString.append(filter.toString()); - toString.append(","); - } - - if (_filters.size() > 0) - { - //Remove the last ',' - toString.deleteCharAt(toString.length()-1); - } - _toString = toString.toString(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/AbstractFlowCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/AbstractFlowCreditManager.java deleted file mode 100644 index 124fb0d1d9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/AbstractFlowCreditManager.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.flow; - -import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicBoolean; - -public abstract class AbstractFlowCreditManager implements FlowCreditManager -{ - private final AtomicBoolean _suspended = new AtomicBoolean(false); - private final ArrayList<FlowCreditManagerListener> _listeners = new ArrayList<FlowCreditManagerListener>(); - - public final void addStateListener(FlowCreditManagerListener listener) - { - synchronized(_listeners) - { - if(!_listeners.contains(listener)) - { - _listeners.add(listener); - } - } - } - - public final boolean removeListener(FlowCreditManagerListener listener) - { - synchronized(_listeners) - { - return _listeners.remove(listener); - } - } - - private void notifyListeners(final boolean suspended) - { - synchronized(_listeners) - { - final int size = _listeners.size(); - for(int i = 0; i<size; i++) - { - _listeners.get(i).creditStateChanged(!suspended); - } - } - } - - protected final void setSuspended(final boolean suspended) - { - if(_suspended.compareAndSet(!suspended, suspended)) - { - notifyListeners(suspended); - } - } - - protected final void notifyIncreaseBytesCredit() - { - notifyListeners(false); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/BytesOnlyCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/BytesOnlyCreditManager.java deleted file mode 100644 index be3a13d2d3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/BytesOnlyCreditManager.java +++ /dev/null @@ -1,87 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.flow; - - -import java.util.concurrent.atomic.AtomicLong; - -public class BytesOnlyCreditManager extends AbstractFlowCreditManager -{ - private final AtomicLong _bytesCredit; - - public BytesOnlyCreditManager(long initialCredit) - { - _bytesCredit = new AtomicLong(initialCredit); - } - - public long getMessageCredit() - { - return -1L; - } - - public long getBytesCredit() - { - return _bytesCredit.get(); - } - - public void restoreCredit(long messageCredit, long bytesCredit) - { - _bytesCredit.addAndGet(bytesCredit); - setSuspended(false); - } - - public void removeAllCredit() - { - _bytesCredit.set(0L); - } - - public boolean hasCredit() - { - return _bytesCredit.get() > 0L; - } - - public boolean useCreditForMessage(long msgSize) - { - if(hasCredit()) - { - if(_bytesCredit.addAndGet(-msgSize) >= 0) - { - return true; - } - else - { - _bytesCredit.addAndGet(msgSize); - setSuspended(true); - return false; - } - } - else - { - return false; - } - - } - - public void setBytesCredit(long bytesCredit) - { - _bytesCredit.set( bytesCredit ); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/FlowCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/FlowCreditManager.java deleted file mode 100644 index 280f2851a4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/FlowCreditManager.java +++ /dev/null @@ -1,46 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.flow; - - - -public interface FlowCreditManager -{ - long getMessageCredit(); - - long getBytesCredit(); - - public static interface FlowCreditManagerListener - { - void creditStateChanged(boolean hasCredit); - } - - void addStateListener(FlowCreditManagerListener listener); - - boolean removeListener(FlowCreditManagerListener listener); - - public void restoreCredit(long messageCredit, long bytesCredit); - - public boolean hasCredit(); - - public boolean useCreditForMessage(long msgSize); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/LimitlessCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/LimitlessCreditManager.java deleted file mode 100644 index 89fc60666b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/LimitlessCreditManager.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.flow; - - -public class LimitlessCreditManager extends AbstractFlowCreditManager implements FlowCreditManager -{ - public long getMessageCredit() - { - return -1L; - } - - public long getBytesCredit() - { - return -1L; - } - - public void restoreCredit(long messageCredit, long bytesCredit) - { - } - - public void removeAllCredit() - { - } - - public boolean hasCredit() - { - return true; - } - - public boolean useCreditForMessage(long msgSize) - { - return true; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageAndBytesCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageAndBytesCreditManager.java deleted file mode 100644 index 31c1fda968..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageAndBytesCreditManager.java +++ /dev/null @@ -1,90 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.flow; - - -public class MessageAndBytesCreditManager extends AbstractFlowCreditManager implements FlowCreditManager -{ - private long _messageCredit; - private long _bytesCredit; - - public MessageAndBytesCreditManager(final long messageCredit, final long bytesCredit) - { - _messageCredit = messageCredit; - _bytesCredit = bytesCredit; - } - - public synchronized long getMessageCredit() - { - return _messageCredit; - } - - public synchronized long getBytesCredit() - { - return _bytesCredit; - } - - public synchronized void restoreCredit(long messageCredit, long bytesCredit) - { - _messageCredit += messageCredit; - _bytesCredit += bytesCredit; - setSuspended(hasCredit()); - } - - public synchronized void removeAllCredit() - { - _messageCredit = 0L; - _bytesCredit = 0L; - setSuspended(true); - } - - public synchronized boolean hasCredit() - { - return (_messageCredit > 0L) && ( _bytesCredit > 0L ); - } - - public synchronized boolean useCreditForMessage(final long msgSize) - { - if(_messageCredit == 0L) - { - setSuspended(true); - return false; - } - else - { - if(msgSize > _bytesCredit) - { - setSuspended(true); - return false; - } - _messageCredit--; - _bytesCredit -= msgSize; - setSuspended(false); - return true; - } - - } - - public synchronized void setBytesCredit(long bytesCredit) - { - _bytesCredit = bytesCredit; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageOnlyCreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageOnlyCreditManager.java deleted file mode 100644 index 1817e8ad31..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/MessageOnlyCreditManager.java +++ /dev/null @@ -1,86 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.flow; - -import java.util.concurrent.atomic.AtomicLong; - -public class MessageOnlyCreditManager extends AbstractFlowCreditManager implements FlowCreditManager -{ - private final AtomicLong _messageCredit; - - public MessageOnlyCreditManager(final long initialCredit) - { - _messageCredit = new AtomicLong(initialCredit); - } - - public long getMessageCredit() - { - return _messageCredit.get(); - } - - public long getBytesCredit() - { - return -1L; - } - - public void restoreCredit(long messageCredit, long bytesCredit) - { - _messageCredit.addAndGet(messageCredit); - setSuspended(false); - - } - - public void removeAllCredit() - { - setSuspended(true); - _messageCredit.set(0L); - } - - public boolean hasCredit() - { - return _messageCredit.get() > 0L; - } - - public boolean useCreditForMessage(long msgSize) - { - if(hasCredit()) - { - if(_messageCredit.addAndGet(-1L) >= 0) - { - setSuspended(false); - return true; - } - else - { - _messageCredit.addAndGet(1L); - setSuspended(true); - return false; - } - } - else - { - setSuspended(true); - return false; - } - - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/Pre0_10CreditManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/Pre0_10CreditManager.java deleted file mode 100644 index fc2d4bfb53..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/flow/Pre0_10CreditManager.java +++ /dev/null @@ -1,192 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.flow; - - -public class Pre0_10CreditManager extends AbstractFlowCreditManager implements FlowCreditManager -{ - - private volatile long _bytesCreditLimit; - private volatile long _messageCreditLimit; - - private volatile long _bytesCredit; - private volatile long _messageCredit; - - public Pre0_10CreditManager(long bytesCreditLimit, long messageCreditLimit) - { - _bytesCreditLimit = bytesCreditLimit; - _messageCreditLimit = messageCreditLimit; - _bytesCredit = bytesCreditLimit; - _messageCredit = messageCreditLimit; - } - - - public synchronized void setCreditLimits(final long bytesCreditLimit, final long messageCreditLimit) - { - long bytesCreditChange = bytesCreditLimit - _bytesCreditLimit; - long messageCreditChange = messageCreditLimit - _messageCreditLimit; - - - - if(bytesCreditChange != 0L) - { - if(bytesCreditLimit == 0L) - { - _bytesCredit = 0; - } - else - { - _bytesCredit += bytesCreditChange; - } - } - - - if(messageCreditChange != 0L) - { - if(messageCreditLimit == 0L) - { - _messageCredit = 0; - } - else - { - _messageCredit += messageCreditChange; - } - } - - - _bytesCreditLimit = bytesCreditLimit; - _messageCreditLimit = messageCreditLimit; - - setSuspended(!hasCredit()); - - } - - - public long getMessageCredit() - { - return _messageCredit; - } - - public long getBytesCredit() - { - return _bytesCredit; - } - - public synchronized void restoreCredit(final long messageCredit, final long bytesCredit) - { - final long messageCreditLimit = _messageCreditLimit; - boolean notifyIncrease = true; - if(messageCreditLimit != 0L) - { - notifyIncrease = (_messageCredit != 0); - long newCredit = _messageCredit + messageCredit; - _messageCredit = newCredit > messageCreditLimit ? messageCreditLimit : newCredit; - } - - - final long bytesCreditLimit = _bytesCreditLimit; - if(bytesCreditLimit != 0L) - { - long newCredit = _bytesCredit + bytesCredit; - _bytesCredit = newCredit > bytesCreditLimit ? bytesCreditLimit : newCredit; - if(notifyIncrease && bytesCredit>0) - { - notifyIncreaseBytesCredit(); - } - } - - - - setSuspended(!hasCredit()); - - } - - public synchronized void removeAllCredit() - { - _bytesCredit = 0L; - _messageCredit = 0L; - setSuspended(!hasCredit()); - } - - public synchronized boolean hasCredit() - { - return (_bytesCreditLimit == 0L || _bytesCredit > 0) - && (_messageCreditLimit == 0L || _messageCredit > 0); - } - - public synchronized boolean useCreditForMessage(final long msgSize) - { - if(_messageCreditLimit != 0L) - { - if(_messageCredit != 0L) - { - if(_bytesCreditLimit == 0L) - { - _messageCredit--; - - return true; - } - else - { - if((_bytesCredit >= msgSize) || (_bytesCredit == _bytesCreditLimit)) - { - _messageCredit--; - _bytesCredit -= msgSize; - - return true; - } - else - { - return false; - } - } - } - else - { - setSuspended(true); - return false; - } - } - else - { - if(_bytesCreditLimit == 0L) - { - - return true; - } - else - { - if((_bytesCredit >= msgSize) || (_bytesCredit == _bytesCreditLimit)) - { - _bytesCredit -= msgSize; - - return true; - } - else - { - return false; - } - } - - } - - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java deleted file mode 100644 index 98da9074ef..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - - -public abstract class AbstractRootMessageLogger implements RootMessageLogger -{ - public static final String DEFAULT_LOG_HIERARCHY_PREFIX = "qpid.message."; - - private boolean _enabled = true; - - public AbstractRootMessageLogger() - { - - } - - public AbstractRootMessageLogger(boolean statusUpdatesEnabled) - { - _enabled = statusUpdatesEnabled; - } - - public boolean isEnabled() - { - return _enabled; - } - - public boolean isMessageEnabled(LogActor actor, LogSubject subject, String logHierarchy) - { - return _enabled; - } - - public boolean isMessageEnabled(LogActor actor, String logHierarchy) - { - return _enabled; - } - - public abstract void rawMessage(String message, String logHierarchy); - - public abstract void rawMessage(String message, Throwable throwable, String logHierarchy); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/CompositeStartupMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/CompositeStartupMessageLogger.java deleted file mode 100644 index e0a51b3a3e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/CompositeStartupMessageLogger.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - -public class CompositeStartupMessageLogger extends AbstractRootMessageLogger -{ - private RootMessageLogger[] _loggers; - - public CompositeStartupMessageLogger(RootMessageLogger[] loggers) - { - super(); - _loggers = loggers; - } - - @Override - public void rawMessage(String message, String logHierarchy) - { - for(RootMessageLogger l : _loggers) - { - l.rawMessage(message, logHierarchy); - } - } - - @Override - public void rawMessage(String message, Throwable throwable, String logHierarchy) - { - for(RootMessageLogger l : _loggers) - { - l.rawMessage(message, throwable, logHierarchy); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java deleted file mode 100644 index b4e9f2f333..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - -import org.apache.log4j.Logger; - -public class Log4jMessageLogger extends AbstractRootMessageLogger -{ - public Log4jMessageLogger() - { - super(); - } - - public Log4jMessageLogger(boolean statusUpdatesEnabled) - { - super(statusUpdatesEnabled); - } - - @Override - public boolean isMessageEnabled(LogActor actor, LogSubject subject, String logHierarchy) - { - return isMessageEnabled(actor, logHierarchy); - } - - @Override - public boolean isMessageEnabled(LogActor actor, String logHierarchy) - { - if(isEnabled()) - { - Logger logger = Logger.getLogger(logHierarchy); - return logger.isInfoEnabled(); - } - else - { - return false; - } - } - - @Override - public void rawMessage(String message, String logHierarchy) - { - rawMessage(message, null, logHierarchy); - } - - @Override - public void rawMessage(String message, Throwable throwable, String logHierarchy) - { - Logger logger = Logger.getLogger(logHierarchy); - logger.info(message, throwable); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogActor.java deleted file mode 100644 index 18f03c2716..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogActor.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - -/** - * LogActor the entity that is stored as in a ThreadLocal and used to perform logging. - * - * The actor is responsible for formatting its display name for the log entry. - * - * The actor performs the requested logging. - */ -public interface LogActor -{ - /** - * Logs the specified LogMessage about the LogSubject - * - * Currently logging has a global setting however this will later be revised and - * as such the LogActor will need to take into consideration any new configuration - * as a means of enabling the logging of LogActors and LogSubjects. - * - * @param subject The subject that is being logged - * @param message The message to log - */ - public void message(LogSubject subject, LogMessage message); - - /** - * Logs the specified LogMessage against this actor - * - * Currently logging has a global setting however this will later be revised and - * as such the LogActor will need to take into consideration any new configuration - * as a means of enabling the logging of LogActors and LogSubjects. - * - * @param message The message to log - */ - public void message(LogMessage message); - - /** - * - * @return the RootMessageLogger that is currently in use by this LogActor. - */ - RootMessageLogger getRootMessageLogger(); - - /** - * - * @return the String representing this LogActor - */ - public String getLogMessage(); -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogMessage.java deleted file mode 100644 index fa18435fab..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogMessage.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - -public interface LogMessage -{ - String getLogHierarchy(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java deleted file mode 100644 index dfffbdbb5f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.qpid.server.logging; - -import java.util.Iterator; -import org.apache.log4j.Appender; -import org.apache.log4j.Layout; -import org.apache.log4j.Logger; -import org.apache.log4j.spi.ErrorHandler; -import org.apache.log4j.spi.Filter; -import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.spi.ThrowableInformation; -import org.apache.qpid.server.configuration.BrokerProperties; - -public class LogRecorder implements Appender, Iterable<LogRecorder.Record> -{ - private static final int DEFAULT_BUFFER_SIZE = 4096; - private ErrorHandler _errorHandler; - private Filter _filter; - private String _name; - private long _recordId; - - private final int _bufferSize = Integer.getInteger(BrokerProperties.PROPERTY_LOG_RECORDS_BUFFER_SIZE, DEFAULT_BUFFER_SIZE); - private final int _mask = _bufferSize - 1; - private Record[] _records = new Record[_bufferSize]; - - - public static class Record - { - private final long _id; - private final String _logger; - private final long _timestamp; - private final String _threadName; - private final String _level; - private final String _message; - - - public Record(long id, LoggingEvent event) - { - _id = id; - _logger = event.getLoggerName(); - _timestamp = event.timeStamp; - _threadName = event.getThreadName(); - _level = event.getLevel().toString(); - StringBuilder message = new StringBuilder(); - String renderedMessage = event.getRenderedMessage(); - if (renderedMessage != null) - { - message.append(renderedMessage); - } - ThrowableInformation ti = event.getThrowableInformation(); - if (ti != null) - { - Throwable t = ti.getThrowable(); - if (t != null) - { - if (message.length() > 0) - { - message.append(":"); - } - String exceptionMessage = t.getMessage(); - if (exceptionMessage != null && !"".equals(exceptionMessage)) - { - message.append(t.getMessage()); - } - else - { - message.append(t.getClass().getName()); - } - } - } - _message = message.toString(); - } - - public long getId() - { - return _id; - } - - public long getTimestamp() - { - return _timestamp; - } - - public String getThreadName() - { - return _threadName; - } - - public String getLevel() - { - return _level; - } - - public String getMessage() - { - return _message; - } - - public String getLogger() - { - return _logger; - } - } - - public LogRecorder() - { - Logger.getRootLogger().addAppender(this); - } - - @Override - public void addFilter(Filter filter) - { - _filter = filter; - } - - @Override - public void clearFilters() - { - _filter = null; - } - - @Override - public void close() - { - } - - public void closeLogRecorder() - { - Logger.getRootLogger().removeAppender(this); - } - - @Override - public synchronized void doAppend(LoggingEvent loggingEvent) - { - _records[((int) (_recordId & _mask))] = new Record(_recordId, loggingEvent); - _recordId++; - } - - @Override - public ErrorHandler getErrorHandler() - { - return _errorHandler; - } - - @Override - public Filter getFilter() - { - return _filter; - } - - @Override - public Layout getLayout() - { - return null; - } - - @Override - public String getName() - { - return _name; - } - - @Override - public boolean requiresLayout() - { - return false; - } - - @Override - public void setErrorHandler(ErrorHandler errorHandler) - { - _errorHandler = errorHandler; - } - - @Override - public void setLayout(Layout layout) - { - - } - - @Override - public void setName(String name) - { - _name = name; - } - - @Override - public Iterator<Record> iterator() - { - return new RecordIterator(Math.max(_recordId-_bufferSize, 0l)); - } - - private class RecordIterator implements Iterator<Record> - { - private long _id; - - public RecordIterator(long currentRecordId) - { - _id = currentRecordId; - } - - @Override - public boolean hasNext() - { - return _id < _recordId; - } - - @Override - public Record next() - { - Record record = _records[((int) (_id & _mask))]; - while(_id < _recordId-_bufferSize) - { - _id = _recordId-_bufferSize; - record = _records[((int) (_id & _mask))]; - } - _id++; - return record; - } - - @Override - public void remove() - { - throw new UnsupportedOperationException(); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogSubject.java deleted file mode 100644 index 09a277e520..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogSubject.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - -/** - * Each LogSubject that wishes to be logged will implement this to provide their - * own display representation. - * - */ -public interface LogSubject -{ - /** - * Provides the log message as as String. - * - * @returns String the display representation of this LogSubject - */ - public String toLogString(); -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/NullRootMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/NullRootMessageLogger.java deleted file mode 100644 index db8b24e90e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/NullRootMessageLogger.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - -public class NullRootMessageLogger extends AbstractRootMessageLogger -{ - - @Override - public boolean isMessageEnabled(LogActor actor, LogSubject subject, String logHeirarchy) - { - return false; - } - - @Override - public boolean isMessageEnabled(LogActor actor, String logHierarchy) - { - return false; - } - - public void rawMessage(String message, String logHierarchy) - { - // drop message - } - - public void rawMessage(String message, Throwable throwable, String logHierarchy) - { - // drop message - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/RootMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/RootMessageLogger.java deleted file mode 100644 index 1431dd1da9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/RootMessageLogger.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - -/** - * The RootMessageLogger is used by the LogActors to query if - * logging is enabled for the requested message and to provide the actual - * message that should be logged. - */ -public interface RootMessageLogger -{ - /** - * Determine whether the MessageLogger is enabled - * - * @return boolean true if enabled. - */ - boolean isEnabled(); - - /** - * Determine if the LogSubject and the LogActor should be - * generating log messages. - * @param actor The actor requesting the logging - * @param subject The subject of this log request - * @param logHierarchy The log hierarchy for this request - * - * @return boolean true if the message should be logged. - */ - boolean isMessageEnabled(LogActor actor, LogSubject subject, String logHierarchy); - - /** - * Determine if the LogActor should be generating log messages. - * - * @param actor The actor requesting the logging - * @param logHierarchy The log hierarchy for this request - * - * @return boolean true if the message should be logged. - */ - boolean isMessageEnabled(LogActor actor, String logHierarchy); - - /** - * Log the raw message to the configured logger. - * - * @param message The message to log - * @param logHierarchy The log hierarchy for this request - */ - public void rawMessage(String message, String logHierarchy); - - /** - * Log the raw message to the configured logger. - * Along with a formated stack trace from the Throwable. - * - * @param message The message to log - * @param throwable Optional Throwable that should provide stact trace - * @param logHierarchy The log hierarchy for this request - */ - void rawMessage(String message, Throwable throwable, String logHierarchy); -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/SystemOutMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/SystemOutMessageLogger.java deleted file mode 100644 index b384b3fde3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/SystemOutMessageLogger.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging; - - -public class SystemOutMessageLogger extends AbstractRootMessageLogger -{ - @Override - public boolean isMessageEnabled(LogActor actor, LogSubject subject, String logHeirarchy) - { - return true; - } - - @Override - public boolean isMessageEnabled(LogActor actor, String logHierarchy) - { - return true; - } - - public void rawMessage(String message, String logHierarchy) - { - rawMessage(message, null, logHierarchy); - } - - public void rawMessage(String message, Throwable throwable, String logHierarchy) - { - System.out.println(message); - if (throwable != null) - { - throwable.printStackTrace(System.out); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AMQPChannelActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AMQPChannelActor.java deleted file mode 100644 index d23122ac5d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AMQPChannelActor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.subjects.ChannelLogSubject; - -/** - * An AMQPChannelActor represtents a connection through the AMQP port with an - * associated Channel. - * - * <p/> - * This is responsible for correctly formatting the LogActor String in the log - * <p/> - * [con:1(user@127.0.0.1/)/ch:1] - * <p/> - * To do this it requires access to the IO Layers as well as a Channel - */ -public class AMQPChannelActor extends AbstractActor -{ - private final ChannelLogSubject _logString; - - /** - * Create a new ChannelActor - * - * @param channel The Channel for this LogActor - * @param rootLogger The root Logger that this LogActor should use - */ - public AMQPChannelActor(AMQSessionModel channel, RootMessageLogger rootLogger) - { - super(rootLogger); - - - _logString = new ChannelLogSubject(channel); - } - - public String getLogMessage() - { - return _logString.toLogString(); - } -} - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AMQPConnectionActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AMQPConnectionActor.java deleted file mode 100644 index 99e11bf9ae..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AMQPConnectionActor.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.subjects.ConnectionLogSubject; -import org.apache.qpid.server.protocol.AMQConnectionModel; - - -/** - * An AMQPConnectionActor represtents a connectionthrough the AMQP port. - * <p/> - * This is responsible for correctly formatting the LogActor String in the log - * <p/> - * [ con:1(user@127.0.0.1/) ] - * <p/> - * To do this it requires access to the IO Layers. - */ -public class AMQPConnectionActor extends AbstractActor -{ - private ConnectionLogSubject _logSubject; - - public AMQPConnectionActor(AMQConnectionModel session, RootMessageLogger rootLogger) - { - super(rootLogger); - - _logSubject = new ConnectionLogSubject(session); - } - - public String getLogMessage() - { - return _logSubject.toLogString(); - } -} - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractActor.java deleted file mode 100644 index e8c6c9c323..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractActor.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.logging.LogMessage; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.logging.RootMessageLogger; - -public abstract class AbstractActor implements LogActor -{ - private final String _msgPrefix = System.getProperty("qpid.logging.prefix",""); - - private RootMessageLogger _rootLogger; - - public AbstractActor(RootMessageLogger rootLogger) - { - if(rootLogger == null) - { - throw new NullPointerException("RootMessageLogger cannot be null"); - } - _rootLogger = rootLogger; - } - - public void message(LogSubject subject, LogMessage message) - { - if (_rootLogger.isMessageEnabled(this, subject, message.getLogHierarchy())) - { - _rootLogger.rawMessage(_msgPrefix + getLogMessage() + subject.toLogString() + message, message.getLogHierarchy()); - } - } - - public void message(LogMessage message) - { - if (_rootLogger.isMessageEnabled(this, message.getLogHierarchy())) - { - _rootLogger.rawMessage(_msgPrefix + getLogMessage() + message, message.getLogHierarchy()); - } - } - - public RootMessageLogger getRootMessageLogger() - { - return _rootLogger; - } - - public String toString() - { - return getLogMessage(); - } - - abstract public String getLogMessage(); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java deleted file mode 100644 index 8cf121b3d9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import java.security.AccessController; - -import javax.security.auth.Subject; - -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.security.auth.AuthenticatedPrincipal; - -public abstract class AbstractManagementActor extends AbstractActor -{ - /** - * Holds the principal name to display when principal subject is not available. - * <p> - * This is useful for cases when users invoke JMX operation over JConsole - * attached to the local JVM. - */ - protected static final String UNKNOWN_PRINCIPAL = "N/A"; - - /** used when the principal name cannot be discovered from the Subject */ - private final String _fallbackPrincipalName; - - public AbstractManagementActor(RootMessageLogger rootLogger, String fallbackPrincipalName) - { - super(rootLogger); - _fallbackPrincipalName = fallbackPrincipalName; - } - - /** - * Returns current {@link AuthenticatedPrincipal} name or {@link #_fallbackPrincipalName} - * if it can't be found. - */ - protected String getPrincipalName() - { - String identity = _fallbackPrincipalName; - - final Subject subject = Subject.getSubject(AccessController.getContext()); - if (subject != null) - { - AuthenticatedPrincipal authenticatedPrincipal = AuthenticatedPrincipal.getOptionalAuthenticatedPrincipalFromSubject(subject); - if(authenticatedPrincipal != null) - { - identity = authenticatedPrincipal.getName(); - } - } - return identity; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java deleted file mode 100644 index 9e77452228..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import org.apache.qpid.server.logging.RootMessageLogger; - -public class BrokerActor extends AbstractActor -{ - private final String _logString; - - /** - * Create a new BrokerActor - * - * @param logger - */ - public BrokerActor(RootMessageLogger logger) - { - super(logger); - - _logString = "[Broker] "; - } - - public BrokerActor(String name, RootMessageLogger logger) - { - super(logger); - - _logString = "[Broker(" + name + ")] "; - } - - public String getLogMessage() - { - return _logString; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java deleted file mode 100644 index 6251471139..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import java.util.EmptyStackException; -import java.util.Stack; - -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.logging.LogMessage; -import org.apache.qpid.server.logging.LogSubject; - -/** - * The CurrentActor is a ThreadLocal wrapper that allows threads in the broker - * to retrieve an actor to perform logging. This approach is used so for two - * reasons: - * 1) We do not have to pass a logging actor around the system - * 2) We can set new actors at the point we have enough information. i.e. - * - Set a low level ConnectionActor when processing bytes from the wire. - * - Set a ChannelActor when we are processing the frame - * - Set a SubscriptionActor when we are handling the subscription. - * <p/> - * The code performing the logging need not worry about what type of actor is - * currently set so can perform its logging. The resulting log entry though will - * contain customised details from the the currently set Actor. - * <p/> - * The Actor model also allows the pre-creation of fixed messages so the - * performance impact of the additional logging data is minimised. - * <p/> - * This class does not perform any checks to ensure that there is an Actor set - * when calling remove or get. As a result the application developer must ensure - * that they have called set before they attempt to use the actor via get or - * remove the set actor. - * <p/> - * The checking of the return via get should not be done as the logging is - * desired. It is preferable to cause the NullPointerException to highlight the - * programming error rather than miss a log message. - * <p/> - * The same is true for the remove. A NPE will occur if no set has been called - * highlighting the programming error. - */ -public class CurrentActor -{ - /** The ThreadLocal variable with initialiser */ - private static final ThreadLocal<Stack<LogActor>> _currentActor = new ThreadLocal<Stack<LogActor>>() - { - // Initialise the CurrentActor to be an empty List - protected Stack<LogActor> initialValue() - { - return new Stack<LogActor>(); - } - }; - - private static LogActor _defaultActor; - - private CurrentActor() - { - } - - /** - * Set a new {@link LogActor} to be the Current Actor - * <p/> - * This pushes the Actor in to the LIFO Queue - * - * @param actor The new LogActor - */ - public static void set(LogActor actor) - { - Stack<LogActor> stack = _currentActor.get(); - stack.push(actor); - } - - /** - * Remove all {@link LogActor}s - */ - public static void removeAll() - { - Stack<LogActor> stack = _currentActor.get(); - stack.clear(); - } - - /** - * Remove the current {@link LogActor}. - * <p/> - * Calling remove without calling set will result in an EmptyStackException. - */ - public static void remove() - { - Stack<LogActor> stack = _currentActor.get(); - stack.pop(); - - if (stack.isEmpty()) - { - _currentActor.remove(); - } - } - - /** - * Return the current head of the list of {@link LogActor}s. - * - * @return Current LogActor - */ - public static LogActor get() - { - try - { - return _currentActor.get().peek(); - } - catch (EmptyStackException ese) - { - return _defaultActor; - } - } - - public static void setDefault(LogActor defaultActor) - { - _defaultActor = defaultActor; - } - - public static void message(LogSubject subject, LogMessage message) - { - get().message(subject, message); - } - - public static void message(LogMessage message) - { - get().message(message); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/GenericActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/GenericActor.java deleted file mode 100644 index 0e418a95e2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/GenericActor.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.logging.RootMessageLogger; - -public class GenericActor extends AbstractActor -{ - - private static RootMessageLogger _defaultMessageLogger; - - private LogSubject _logSubject; - - public static RootMessageLogger getDefaultMessageLogger() - { - return _defaultMessageLogger; - } - - public static void setDefaultMessageLogger(RootMessageLogger defaultMessageLogger) - { - _defaultMessageLogger = defaultMessageLogger; - } - - public GenericActor(LogSubject logSubject, RootMessageLogger rootLogger) - { - super(rootLogger); - _logSubject = logSubject; - } - - public String getLogMessage() - { - return _logSubject.toLogString(); - } - - public static LogActor getInstance(final String logMessage, RootMessageLogger rootLogger) - { - return new GenericActor(new LogSubject() - { - public String toLogString() - { - return logMessage; - } - - }, rootLogger); - } - - public static LogActor getInstance(final String subjectMessage) - { - return new GenericActor(new LogSubject() - { - public String toLogString() - { - return "[" + subjectMessage + "] "; - } - - }, _defaultMessageLogger); - } - - public static LogActor getInstance(LogSubject logSubject) - { - return new GenericActor(logSubject, _defaultMessageLogger); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java deleted file mode 100644 index 9b445c2bd9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import java.text.MessageFormat; - -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.subjects.LogSubjectFormat; - -/** - * HttpManagement actor to use in {@link AbstractServlet} to log all http management operational logging. - * - * An instance is required per http Session. - */ -public class HttpManagementActor extends AbstractManagementActor -{ - private String _cachedLogString; - private String _lastPrincipalName; - private String _address; - - public HttpManagementActor(RootMessageLogger rootLogger, String ip, int port) - { - super(rootLogger, UNKNOWN_PRINCIPAL); - _address = ip + ":" + port; - } - - private synchronized String getAndCacheLogString() - { - String principalName = getPrincipalName(); - - if(!principalName.equals(_lastPrincipalName)) - { - _lastPrincipalName = principalName; - _cachedLogString = "[" + MessageFormat.format(LogSubjectFormat.MANAGEMENT_FORMAT, principalName, _address) + "] "; - } - - return _cachedLogString; - } - - public String getLogMessage() - { - return getAndCacheLogString(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java deleted file mode 100644 index ba5ea47fc1..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.subjects.LogSubjectFormat; - -import java.text.MessageFormat; - -/** - * Management actor to use in {@link MBeanInvocationHandlerImpl} to log all management operational logging. - */ -public class ManagementActor extends AbstractManagementActor -{ - private String _lastThreadName = null; - - /** - * The logString to be used for logging - */ - private String _logStringContainingPrincipal; - - /** @param rootLogger The RootLogger to use for this Actor */ - public ManagementActor(RootMessageLogger rootLogger) - { - super(rootLogger, UNKNOWN_PRINCIPAL); - } - - public ManagementActor(RootMessageLogger rootLogger, String principalName) - { - super(rootLogger, principalName); - } - - private synchronized String getAndCacheLogString() - { - String currentName = Thread.currentThread().getName(); - - String actor; - String logString = _logStringContainingPrincipal; - - // Record the last thread name so we don't have to recreate the log string - if (_logStringContainingPrincipal == null || !currentName.equals(_lastThreadName)) - { - _lastThreadName = currentName; - String principalName = getPrincipalName(); - - // Management Thread names have this format. - // RMI TCP Connection(2)-169.24.29.116 - // This is true for both LocalAPI and JMX Connections - // However to be defensive lets test. - String[] split = currentName.split("\\("); - if (split.length == 2) - { - String ip = currentName.split("-")[1]; - actor = MessageFormat.format(LogSubjectFormat.MANAGEMENT_FORMAT, principalName, ip); - } - else - { - // This is a precautionary path as it is not expected to occur - // however rather than adjusting the thread name of the two - // tests that will use this it is safer all round to do this. - // it is also currently used by tests : - // AMQBrokerManagerMBeanTest - // ExchangeMBeanTest - actor = currentName; - } - - logString = "[" + actor + "] "; - if(principalName != UNKNOWN_PRINCIPAL ) - { - _logStringContainingPrincipal = logString; - } - - } - return logString; - } - - public String getLogMessage() - { - return getAndCacheLogString(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/QueueActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/QueueActor.java deleted file mode 100644 index 4b17e8c0e6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/QueueActor.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.subjects.QueueLogSubject; -import org.apache.qpid.server.queue.AMQQueue; - -/** - * This Actor is used when while the queue is performing an asynchronous process - * of its queue. - */ -public class QueueActor extends AbstractActor -{ - private QueueLogSubject _logSubject; - - /** - * Create an QueueLogSubject that Logs in the following format. - * - * @param queue The queue that this Actor is working for - * @param rootLogger the Root logger to use. - */ - public QueueActor(AMQQueue queue, RootMessageLogger rootLogger) - { - super(rootLogger); - - _logSubject = new QueueLogSubject(queue); - } - - public String getLogMessage() - { - return _logSubject.toLogString(); - } -} - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/SubscriptionActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/SubscriptionActor.java deleted file mode 100644 index a2dbf2f6ee..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/SubscriptionActor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.actors; - -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.subjects.SubscriptionLogSubject; -import org.apache.qpid.server.subscription.Subscription; - -/** - * The subscription actor provides formatted logging for actions that are - * performed by the subsciption. Such as STATE changes. - */ -public class SubscriptionActor extends AbstractActor -{ - private SubscriptionLogSubject _logSubject; - - public SubscriptionActor(RootMessageLogger logger, Subscription subscription) - { - super(logger); - - _logSubject = new SubscriptionLogSubject(subscription); - } - - public String getLogMessage() - { - return _logSubject.toLogString(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingFacadeException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingFacadeException.java deleted file mode 100644 index 468b06be34..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingFacadeException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.log4j; - -public class LoggingFacadeException extends Exception -{ - - public LoggingFacadeException() - { - super(); - } - - public LoggingFacadeException(String message, Throwable cause) - { - super(message, cause); - } - - public LoggingFacadeException(String message) - { - super(message); - } - - public LoggingFacadeException(Throwable cause) - { - super(cause); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java deleted file mode 100644 index 6a961c8fa4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java +++ /dev/null @@ -1,579 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.log4j; - -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; -import org.apache.log4j.xml.Log4jEntityResolver; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -/** - * A facade over log4j that allows both the control of the runtime logging behaviour (that is, the ability to - * turn {@link Logger} on, off and control their {@link Level}, and the manipulation and reload - * of the log4j configuration file. - */ -public class LoggingManagementFacade -{ - private static Logger LOGGER; - private static transient LoggingManagementFacade _instance; - private final String _filename; - private final int _delay; - - public static LoggingManagementFacade configure(String filename) throws LoggingFacadeException - { - _instance = new LoggingManagementFacade(filename); - return _instance; - } - - public static LoggingManagementFacade configureAndWatch(String filename, int delay) throws LoggingFacadeException - { - _instance = new LoggingManagementFacade(filename, delay); - return _instance; - } - - public static LoggingManagementFacade getCurrentInstance() - { - return _instance; - } - - private LoggingManagementFacade(String filename) - { - DOMConfigurator.configure(filename); - - if(LOGGER == null) - { - LOGGER = Logger.getLogger(LoggingManagementFacade.class); - } - _filename = filename; - _delay = 0; - } - - private LoggingManagementFacade(String filename, int delay) - { - DOMConfigurator.configureAndWatch(filename, delay); - - if(LOGGER == null) - { - LOGGER = Logger.getLogger(LoggingManagementFacade.class); - } - - _filename = filename; - _delay = delay; - } - - public int getLog4jLogWatchInterval() - { - return _delay; - } - - public synchronized void reload() throws LoggingFacadeException - { - DOMConfigurator.configure(_filename); - } - - /** The log4j XML configuration file DTD defines three possible element - * combinations for specifying optional logger+level settings. - * Must account for the following: - * - * <category name="x"> <priority value="y"/> </category> OR - * <category name="x"> <level value="y"/> </category> OR - * <logger name="x"> <level value="y"/> </logger> - * - * Noting also that the level/priority child element is optional too, - * and not the only possible child element. - */ - public synchronized Map<String,String> retrieveConfigFileLoggersLevels() throws LoggingFacadeException - { - try - { - Map<String,String> loggerLevelList = new HashMap<String,String>(); - LOGGER.info("Getting logger levels from log4j configuration file"); - - Document doc = parseConfigFile(_filename); - List<Element> categoryOrLoggerElements = buildListOfCategoryOrLoggerElements(doc); - - for (Element categoryOrLogger : categoryOrLoggerElements) - { - - Element priorityOrLevelElement; - try - { - priorityOrLevelElement = getPriorityOrLevelElement(categoryOrLogger); - } - catch (LoggingFacadeException lfe) - { - //there is no exiting priority or level to view, move onto next category/logger - continue; - } - - String categoryName = categoryOrLogger.getAttribute("name"); - String priorityOrLevelValue = priorityOrLevelElement.getAttribute("value"); - loggerLevelList.put(categoryName, priorityOrLevelValue); - } - - return loggerLevelList; - } - catch (IOException e) - { - throw new LoggingFacadeException(e); - } - } - - /** - * The log4j XML configuration file DTD defines 2 possible element - * combinations for specifying the optional root logger level settings - * Must account for the following: - * - * <root> <priority value="y"/> </root> OR - * <root> <level value="y"/> </root> - * - * Noting also that the level/priority child element is optional too, - * and not the only possible child element. - */ - public synchronized String retrieveConfigFileRootLoggerLevel() throws LoggingFacadeException - { - try - { - Document doc = parseConfigFile(_filename); - - //retrieve the optional 'root' element node - NodeList rootElements = doc.getElementsByTagName("root"); - - if (rootElements.getLength() == 0) - { - //there is no root logger definition - return "N/A"; - } - - Element rootElement = (Element) rootElements.item(0); - Element levelElement = getPriorityOrLevelElement(rootElement); - - if(levelElement != null) - { - return levelElement.getAttribute("value"); - } - else - { - return "N/A"; - } - } - catch (IOException e) - { - throw new LoggingFacadeException(e); - } - } - - public synchronized void setConfigFileLoggerLevel(String logger, String level) throws LoggingFacadeException - { - LOGGER.info("Setting level to " + level + " for logger '" + logger - + "' in log4j xml configuration file: " + _filename); - - try - { - Document doc = parseConfigFile(_filename); - - List<Element> logElements = buildListOfCategoryOrLoggerElements(doc); - - //try to locate the specified logger/category in the elements retrieved - Element logElement = null; - for (Element e : logElements) - { - if (e.getAttribute("name").equals(logger)) - { - logElement = e; - break; - } - } - - if (logElement == null) - { - throw new LoggingFacadeException("Can't find logger " + logger); - } - - Element levelElement = getPriorityOrLevelElement(logElement); - - //update the element with the new level/priority - levelElement.setAttribute("value", level); - - //output the new file - writeUpdatedConfigFile(_filename, doc); - } - catch (IOException ioe) - { - throw new LoggingFacadeException(ioe); - } - catch (TransformerConfigurationException e) - { - throw new LoggingFacadeException(e); - } - } - - public synchronized void setConfigFileRootLoggerLevel(String level) throws LoggingFacadeException - { - try - { - LOGGER.info("Setting level to " + level + " for the Root logger in " + - "log4j xml configuration file: " + _filename); - - Document doc = parseConfigFile(_filename); - - //retrieve the optional 'root' element node - NodeList rootElements = doc.getElementsByTagName("root"); - - if (rootElements.getLength() == 0) - { - throw new LoggingFacadeException("Configuration contains no root element"); - } - - Element rootElement = (Element) rootElements.item(0); - Element levelElement = getPriorityOrLevelElement(rootElement); - - //update the element with the new level/priority - levelElement.setAttribute("value", level); - - //output the new file - writeUpdatedConfigFile(_filename, doc); - } - catch (IOException e) - { - throw new LoggingFacadeException(e); - } - catch (TransformerConfigurationException e) - { - throw new LoggingFacadeException(e); - } - } - - public List<String> getAvailableLoggerLevels() - { - return new ArrayList<String>() - {{ - add(Level.ALL.toString()); - add(Level.TRACE.toString()); - add(Level.DEBUG.toString()); - add(Level.INFO.toString()); - add(Level.WARN.toString()); - add(Level.ERROR.toString()); - add(Level.FATAL.toString()); - add(Level.OFF.toString()); - }}; - } - - public String retrieveRuntimeRootLoggerLevel() - { - Logger rootLogger = Logger.getRootLogger(); - return rootLogger.getLevel().toString(); - } - - public void setRuntimeRootLoggerLevel(String level) - { - Level newLevel = Level.toLevel(level); - - LOGGER.info("Setting RootLogger level to " + level); - - Logger log = Logger.getRootLogger(); - log.setLevel(newLevel); - } - - public void setRuntimeLoggerLevel(String loggerName, String level) throws LoggingFacadeException - { - Level newLevel = level == null ? null : Level.toLevel(level); - - Logger targetLogger = findRuntimeLogger(loggerName); - - if(targetLogger == null) - { - throw new LoggingFacadeException("Can't find logger " + loggerName); - } - - LOGGER.info("Setting level to " + newLevel + " for logger '" + targetLogger.getName() + "'"); - - targetLogger.setLevel(newLevel); - } - - public Map<String,String> retrieveRuntimeLoggersLevels() - { - LOGGER.info("Getting levels for currently active log4j loggers"); - - Map<String, String> levels = new HashMap<String, String>(); - @SuppressWarnings("unchecked") - Enumeration<Logger> loggers = LogManager.getCurrentLoggers(); - - while (loggers.hasMoreElements()) - { - Logger logger = loggers.nextElement(); - levels.put(logger.getName(), logger.getEffectiveLevel().toString()); - } - - return levels; - } - - private void writeUpdatedConfigFile(String log4jConfigFileName, Document doc) throws IOException, TransformerConfigurationException - { - File log4jConfigFile = new File(log4jConfigFileName); - - if (!log4jConfigFile.canWrite()) - { - LOGGER.warn("Specified log4j XML configuration file is not writable: " + log4jConfigFile); - throw new IOException("Specified log4j XML configuration file is not writable"); - } - - Transformer transformer = null; - transformer = TransformerFactory.newInstance().newTransformer(); - - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "log4j.dtd"); - DOMSource source = new DOMSource(doc); - - File tmp; - Random r = new Random(); - - do - { - tmp = new File(log4jConfigFile.getAbsolutePath() + r.nextInt() + ".tmp"); - } - while(tmp.exists()); - - tmp.deleteOnExit(); - - try - { - StreamResult result = new StreamResult(new FileOutputStream(tmp)); - transformer.transform(source, result); - } - catch (TransformerException e) - { - LOGGER.warn("Could not transform the XML into new file: ", e); - throw new IOException("Could not transform the XML into new file: ", e); - } - - // Swap temp file in to replace existing configuration file. - File old = new File(log4jConfigFile.getAbsoluteFile() + ".old"); - if (old.exists()) - { - old.delete(); - } - - if(!log4jConfigFile.renameTo(old)) - { - //unable to rename the existing file to the backup name - LOGGER.error("Could not backup the existing log4j XML file"); - throw new IOException("Could not backup the existing log4j XML file"); - } - - if(!tmp.renameTo(log4jConfigFile)) - { - //failed to rename the new file to the required filename - - if(!old.renameTo(log4jConfigFile)) - { - //unable to return the backup to required filename - LOGGER.error("Could not rename the new log4j configuration file into place, and unable to restore original file"); - throw new IOException("Could not rename the new log4j configuration file into place, and unable to restore original file"); - } - - LOGGER.error("Could not rename the new log4j configuration file into place"); - throw new IOException("Could not rename the new log4j configuration file into place"); - } - } - - //method to parse the XML configuration file, validating it in the process, and returning a DOM Document of the content. - private static Document parseConfigFile(String fileName) throws IOException - { - //check file was specified, exists, and is readable - if(fileName == null) - { - LOGGER.warn("Provided log4j XML configuration filename is null"); - throw new IOException("Provided log4j XML configuration filename is null"); - } - - File configFile = new File(fileName); - - if (!configFile.exists()) - { - LOGGER.warn("The log4j XML configuration file could not be found: " + fileName); - throw new IOException("The log4j XML configuration file could not be found"); - } - else if (!configFile.canRead()) - { - LOGGER.warn("The log4j XML configuration file is not readable: " + fileName); - throw new IOException("The log4j XML configuration file is not readable"); - } - - //parse it - DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder; - Document doc; - - ErrorHandler errHandler = new QpidLog4JSaxErrorHandler(); - try - { - docFactory.setValidating(true); - docBuilder = docFactory.newDocumentBuilder(); - docBuilder.setErrorHandler(errHandler); - docBuilder.setEntityResolver(new Log4jEntityResolver()); - doc = docBuilder.parse(fileName); - } - catch (ParserConfigurationException e) - { - LOGGER.warn("Unable to parse the log4j XML file due to possible configuration error: ", e); - throw new IOException("Unable to parse the log4j XML file due to possible configuration error: ", e); - } - catch (SAXException e) - { - LOGGER.warn("The specified log4j XML file is invalid: ", e); - throw new IOException("The specified log4j XML file is invalid: ", e); - } - catch (IOException e) - { - LOGGER.warn("Unable to parse the specified log4j XML file", e); - throw new IOException("Unable to parse the specified log4j XML file: ", e); - } - - return doc; - } - - private Logger findRuntimeLogger(String loggerName) - { - Logger targetLogger = null; - @SuppressWarnings("unchecked") - Enumeration<Logger> loggers = LogManager.getCurrentLoggers(); - while(loggers.hasMoreElements()) - { - targetLogger = loggers.nextElement(); - if (targetLogger.getName().equals(loggerName)) - { - return targetLogger; - } - } - return null; - } - - private List<Element> buildListOfCategoryOrLoggerElements(Document doc) - { - //retrieve the 'category' and 'logger' element nodes - NodeList categoryElements = doc.getElementsByTagName("category"); - NodeList loggerElements = doc.getElementsByTagName("logger"); - - //collect them into a single elements list - List<Element> logElements = new ArrayList<Element>(); - - for (int i = 0; i < categoryElements.getLength(); i++) - { - logElements.add((Element) categoryElements.item(i)); - } - for (int i = 0; i < loggerElements.getLength(); i++) - { - logElements.add((Element) loggerElements.item(i)); - } - return logElements; - } - - private Element getPriorityOrLevelElement(Element categoryOrLogger) throws LoggingFacadeException - { - //retrieve the optional 'priority' or 'level' sub-element value. - //It may not be the only child node, so request by tag name. - NodeList priorityElements = categoryOrLogger.getElementsByTagName("priority"); - NodeList levelElements = categoryOrLogger.getElementsByTagName("level"); - - Element levelElement = null; - if (priorityElements.getLength() != 0) - { - levelElement = (Element) priorityElements.item(0); - } - else if (levelElements.getLength() != 0) - { - levelElement = (Element) levelElements.item(0); - } - else - { - throw new LoggingFacadeException("Configuration " + categoryOrLogger.getNodeName() - + " element contains neither priority nor level child"); - } - return levelElement; - } - - private static class QpidLog4JSaxErrorHandler implements ErrorHandler - { - public void error(SAXParseException e) throws SAXException - { - if(LOGGER != null) - { - LOGGER.warn(constructMessage("Error parsing XML file", e)); - } - else - { - System.err.println(constructMessage("Error parsing XML file", e)); - } - } - - public void fatalError(SAXParseException e) throws SAXException - { - throw new SAXException(constructMessage("Fatal error parsing XML file", e)); - } - - public void warning(SAXParseException e) throws SAXException - { - if(LOGGER != null) - { - LOGGER.warn(constructMessage("Warning parsing XML file", e)); - } - else - { - System.err.println(constructMessage("Warning parsing XML file", e)); - } - } - - private static String constructMessage(final String msg, final SAXParseException ex) - { - return msg + ": Line " + ex.getLineNumber()+" column " +ex.getColumnNumber() + ": " + ex.getMessage(); - } - } -} - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Binding_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Binding_logmessages.properties deleted file mode 100644 index 808ec7918f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Binding_logmessages.properties +++ /dev/null @@ -1,22 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. -# -CREATED = BND-1001 : Create[ : Arguments : {0}] -DELETED = BND-1002 : Deleted diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Broker_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Broker_logmessages.properties deleted file mode 100644 index 76c1fa1b5b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Broker_logmessages.properties +++ /dev/null @@ -1,50 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. - -# 0 - Version -# 1 = Build -STARTUP = BRK-1001 : Startup : Version: {0} Build: {1} -# 0 - Transport -# 1 - Port -LISTENING = BRK-1002 : Starting : Listening on {0} port {1,number,#} -# 0 - Transport -# 1 - Port -SHUTTING_DOWN = BRK-1003 : Shutting down : {0} port {1,number,#} -READY = BRK-1004 : Qpid Broker Ready -STOPPED = BRK-1005 : Stopped -# 0 - path -CONFIG = BRK-1006 : Using configuration : {0} -# 0 - path -LOG_CONFIG = BRK-1007 : Using logging configuration : {0} - -STATS_DATA = BRK-1008 : {0,choice,0#delivered|1#received} : {1,number,#.###} kB/s peak : {2,number,#} bytes total -STATS_MSGS = BRK-1009 : {0,choice,0#delivered|1#received} : {1,number,#.###} msg/s peak : {2,number,#} msgs total - -# 0 - java vendor -# 1 - java runtime version -# 2 - os name -# 3 - os type -# 4 - os architecture -PLATFORM = BRK-1010 : Platform : JVM : {0} version: {1} OS : {2} version: {3} arch: {4} - -# 0 Maximum Memory -MAX_MEMORY = BRK-1011 : Maximum Memory : {0,number} bytes - -MANAGEMENT_MODE = BRK-1012 : Management Mode : User Details : {0} / {1}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Channel_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Channel_logmessages.properties deleted file mode 100644 index 397c12d73c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Channel_logmessages.properties +++ /dev/null @@ -1,40 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. - -CREATE = CHN-1001 : Create -# 0 - flow -FLOW = CHN-1002 : Flow {0} -CLOSE = CHN-1003 : Close -CLOSE_FORCED = CHN-1003 : Close : {0,number} - {1} - -# 0 - bytes allowed in prefetch -# 1 - number of messagse. -PREFETCH_SIZE = CHN-1004 : Prefetch Size (bytes) {0,number} : Count {1,number} -# 0 - queue causing flow control -FLOW_ENFORCED = CHN-1005 : Flow Control Enforced (Queue {0}) -FLOW_REMOVED = CHN-1006 : Flow Control Removed -# Channel Transactions -# 0 - time in milliseconds -OPEN_TXN = CHN-1007 : Open Transaction : {0,number} ms -IDLE_TXN = CHN-1008 : Idle Transaction : {0,number} ms - -DISCARDMSG_NOALTEXCH = CHN-1009 : Discarded message : {0,number} as no alternate exchange configured for queue : {1} routing key : {2} -DISCARDMSG_NOROUTE = CHN-1010 : Discarded message : {0,number} as no binding on alternate exchange : {1} -DEADLETTERMSG = CHN-1011 : Message : {0,number} moved to dead letter queue : {1} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ConfigStore_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ConfigStore_logmessages.properties deleted file mode 100644 index 541f8b8c68..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ConfigStore_logmessages.properties +++ /dev/null @@ -1,26 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. - -CREATED = CFG-1001 : Created -# 0 - path -STORE_LOCATION = CFG-1002 : Store location : {0} -CLOSE = CFG-1003 : Closed -RECOVERY_START = CFG-1004 : Recovery Start -RECOVERY_COMPLETE = CFG-1005 : Recovery Complete diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Connection_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Connection_logmessages.properties deleted file mode 100644 index a99bcc7352..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Connection_logmessages.properties +++ /dev/null @@ -1,26 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. - -# 0 - Client id -# 1 - Protocol Version -# 2 - Client Version -OPEN = CON-1001 : Open[ : Client ID : {0}][ : Protocol Version : {1}][ : Client Version : {2}] -CLOSE = CON-1002 : Close -IDLE_CLOSE = CON-1003 : Closed due to inactivity diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Exchange_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Exchange_logmessages.properties deleted file mode 100644 index b25a6a7301..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Exchange_logmessages.properties +++ /dev/null @@ -1,25 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. - -# 0 - type -# 1 - name -CREATED = EXH-1001 : Create :[ Durable] Type: {0} Name: {1} -DELETED = EXH-1002 : Deleted -DISCARDMSG = EXH-1003 : Discarded Message : Name: {0} Routing Key: {1} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties deleted file mode 100644 index 7924be28d3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties +++ /dev/null @@ -1,38 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. -# -# 0 - Management Type -STARTUP = MNG-1001 : {0} Management Startup -# 0 - Service -# 1 - Port -LISTENING = MNG-1002 : Starting : {0} : Listening on port {1,number,#} -# 0 - Service -# 1 - Port -SHUTTING_DOWN = MNG-1003 : Shutting down : {0} : port {1,number,#} -# 0 - Management Type -READY = MNG-1004 : {0} Management Ready -# 0 - Management Type -STOPPED = MNG-1005 : {0} Management Stopped -# 0 - Path -SSL_KEYSTORE = MNG-1006 : Using SSL Keystore : {0} -# 0 - Username -OPEN = MNG-1007 : Open : User {0} -# 0 - Username -CLOSE = MNG-1008 : Close : User {0}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/MessageStore_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/MessageStore_logmessages.properties deleted file mode 100644 index d3823a71a0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/MessageStore_logmessages.properties +++ /dev/null @@ -1,30 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. -# -CREATED = MST-1001 : Created -# 0 - path -STORE_LOCATION = MST-1002 : Store location : {0} -CLOSED = MST-1003 : Closed -RECOVERY_START = MST-1004 : Recovery Start -RECOVERED = MST-1005 : Recovered {0,number} messages -RECOVERY_COMPLETE = MST-1006 : Recovery Complete -PASSIVATE = MST-1007 : Store Passivated -OVERFULL = MST-1008 : Store overfull, flow control will be enforced -UNDERFULL = MST-1009 : Store overfull condition cleared diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Queue_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Queue_logmessages.properties deleted file mode 100644 index 538bf994ea..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Queue_logmessages.properties +++ /dev/null @@ -1,26 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. -# -# 0 - owner -# 1 - priority -CREATED = QUE-1001 : Create :[ Owner: {0}][ AutoDelete][ Durable][ Transient][ Priority: {1,number,#}] -DELETED = QUE-1002 : Deleted -OVERFULL = QUE-1003 : Overfull : Size : {0,number} bytes, Capacity : {1,number} -UNDERFULL = QUE-1004 : Underfull : Size : {0,number} bytes, Resume Capacity : {1,number} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Subscription_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Subscription_logmessages.properties deleted file mode 100644 index ef5f885b50..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/Subscription_logmessages.properties +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. -# -CREATE = SUB-1001 : Create[ : Durable][ : Arguments : {0}] -CLOSE = SUB-1002 : Close -# 0 - The current subscription state -STATE = SUB-1003 : State : {0}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/TransactionLog_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/TransactionLog_logmessages.properties deleted file mode 100644 index b9e87159a6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/TransactionLog_logmessages.properties +++ /dev/null @@ -1,38 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. -# -# -CREATED = TXN-1001 : Created -# 0 - path -STORE_LOCATION = TXN-1002 : Store location : {0} -CLOSED = TXN-1003 : Closed -# 0 - queue name -RECOVERY_START = TXN-1004 : Recovery Start[ : {0}] -# 0 - count -# 1 - queue count -RECOVERED = TXN-1005 : Recovered {0,number} messages for queue {1} -# 0 - queue name -RECOVERY_COMPLETE = TXN-1006 : Recovery Complete[ : {0}] -# 0 - xid -# 1 - queue name -XA_INCOMPLETE_QUEUE = TXN-1007 : XA transaction recover for xid {0} incomplete as it references a queue {1} which was not durably retained -# 0 - xid format -# 1 - message id -XA_INCOMPLETE_MESSAGE = TXN-1008 : XA transaction recover for xid {0} incomplete as it references a message {1} which was not durably retained diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/VirtualHost_logmessages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/VirtualHost_logmessages.properties deleted file mode 100644 index 5695026cbc..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/VirtualHost_logmessages.properties +++ /dev/null @@ -1,28 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -# Default File used for all non-defined locales. -# -# 0 - name -CREATED = VHT-1001 : Created : {0} -CLOSED = VHT-1002 : Closed - -STATS_DATA = VHT-1003 : {0} : {1,choice,0#delivered|1#received} : {2,number,#.###} kB/s peak : {3,number,#} bytes total -STATS_MSGS = VHT-1004 : {0} : {1,choice,0#delivered|1#received} : {2,number,#.###} msg/s peak : {3,number,#} msgs total - -ERRORED = VHT-1005 : Unexpected fatal error
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/AbstractLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/AbstractLogSubject.java deleted file mode 100644 index baccf240ff..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/AbstractLogSubject.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -import org.apache.qpid.server.logging.LogSubject; - -import java.text.MessageFormat; - -/** - * The LogSubjects all have a similar requriement to format their output and - * provide the String value. - * - * This Abstract LogSubject provides this basic functionality, allowing the - * actual LogSubjects to provide their formating and data. - */ -public abstract class AbstractLogSubject implements LogSubject -{ - private String _logString; - - /** - * Set the toString logging of this LogSubject. Based on a format provided - * by format and the var args. - * @param format The Message to format - * @param args The values to put in to the message. - */ - protected void setLogStringWithFormat(String format, Object... args) - { - _logString = "[" + MessageFormat.format(format, args) + "] "; - } - - /** - * toLogString is how the Logging infrastructure will get the text for this - * LogSubject - * - * @return String representing this LogSubject - */ - public String toLogString() - { - return _logString; - } - - /** - * The logString that will be returned via toLogString - */ - public String getLogString() - { - return _logString; - } - - public void setLogString(String logString) - { - _logString = logString; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/BindingLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/BindingLogSubject.java deleted file mode 100644 index a633162e85..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/BindingLogSubject.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.queue.AMQQueue; - -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.BINDING_FORMAT; - -public class BindingLogSubject extends AbstractLogSubject -{ - - /** - * Create a BindingLogSubject that Logs in the following format. - * - * [ vh(/)/ex(amq.direct)/qu(testQueue)/bd(testQueue) ] - * - * @param routingKey - * @param exchange - * @param queue - */ - public BindingLogSubject(String routingKey, Exchange exchange, - AMQQueue queue) - { - setLogStringWithFormat(BINDING_FORMAT, - queue.getVirtualHost().getName(), - exchange.getType().getType(), - exchange.getName(), - queue.getName(), - routingKey); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java deleted file mode 100644 index 5b0e34b73e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -import org.apache.qpid.server.protocol.AMQConnectionModel; -import org.apache.qpid.server.protocol.AMQSessionModel; - -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.CHANNEL_FORMAT; - -public class ChannelLogSubject extends AbstractLogSubject -{ - - public ChannelLogSubject(AMQSessionModel session) - { - /** - * LOG FORMAT used by the AMQPConnectorActor follows - * ChannelLogSubject.CHANNEL_FORMAT : con:{0}({1}@{2}/{3})/ch:{4}. - * - * Uses a MessageFormat call to insert the required values according to - * these indices: - * - * 0 - Connection ID - * 1 - User ID - * 2 - IP - * 3 - Virtualhost - * 4 - Channel ID - */ - AMQConnectionModel connection = session.getConnectionModel(); - setLogStringWithFormat(CHANNEL_FORMAT, - connection == null ? -1L : connection.getConnectionId(), - (connection == null || connection.getPrincipalAsString() == null) ? "?" : connection.getPrincipalAsString(), - (connection == null || connection.getRemoteAddressString() == null) ? "?" : connection.getRemoteAddressString(), - (connection == null || connection.getVirtualHostName() == null) ? "?" : connection.getVirtualHostName(), - session.getChannelId()); - - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubject.java deleted file mode 100644 index 87c2377e0f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubject.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -import java.text.MessageFormat; -import org.apache.qpid.server.protocol.AMQConnectionModel; - -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.CONNECTION_FORMAT; -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.SOCKET_FORMAT; -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.USER_FORMAT; - -/** The Connection LogSubject */ -public class ConnectionLogSubject extends AbstractLogSubject -{ - - // The Session this Actor is representing - private AMQConnectionModel _session; - - public ConnectionLogSubject(AMQConnectionModel session) - { - _session = session; - } - - // Used to stop re-creating the _logString when we reach our final format - private boolean _upToDate = false; - - /** - * Update the LogString as the Connection process proceeds. - * - * When the Session has an authorized ID add that to the string. - * - * When the Session then gains a Vhost add that to the string, at this point - * we can set upToDate = true as the _logString will not need to be updated - * from this point onwards. - */ - private void updateLogString() - { - if (!_upToDate) - { - if (_session.getPrincipalAsString() != null) - { - if (_session.getVirtualHostName() != null) - { - /** - * LOG FORMAT used by the AMQPConnectorActor follows - * ConnectionLogSubject.CONNECTION_FORMAT : - * con:{0}({1}@{2}/{3}) - * - * Uses a MessageFormat call to insert the required values - * according to these indices: - * - * 0 - Connection ID 1 - User ID 2 - IP 3 - Virtualhost - */ - setLogString("[" + MessageFormat.format(CONNECTION_FORMAT, - _session.getConnectionId(), - _session.getPrincipalAsString(), - _session.getRemoteAddressString(), - _session.getVirtualHostName()) - + "] "); - - _upToDate = true; - } - else - { - setLogString("[" + MessageFormat.format(USER_FORMAT, - _session.getConnectionId(), - _session.getPrincipalAsString(), - _session.getRemoteAddressString()) - + "] "); - - } - } - else - { - setLogString("[" + MessageFormat.format(SOCKET_FORMAT, - _session.getConnectionId(), - _session.getRemoteAddressString()) - + "] "); - } - } - } - - public String toLogString() - { - updateLogString(); - return super.toLogString(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubject.java deleted file mode 100644 index 5affafad75..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubject.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.EXCHANGE_FORMAT; - -public class ExchangeLogSubject extends AbstractLogSubject -{ - - /** Create an ExchangeLogSubject that Logs in the following format. */ - public ExchangeLogSubject(Exchange exchange, VirtualHost vhost) - { - setLogStringWithFormat(EXCHANGE_FORMAT, vhost.getName(), - exchange.getType().getType(), exchange.getName()); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/LogSubjectFormat.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/LogSubjectFormat.java deleted file mode 100644 index 7611ee1a88..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/LogSubjectFormat.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -/** - * LogSubjectFormat class contains a list of formatting string - * that can be statically imported where needed. - * The formatting strings are to be used via a MessageFormat call - * to insert the required values at the corresponding place holder - * indices. - * - */ - -public class LogSubjectFormat -{ - - private LogSubjectFormat() - { - } - - /** - * LOG FORMAT for the ManagementActors, - * 0 - User ID - * 1 - IP[:Port] - */ - public static final String MANAGEMENT_FORMAT = "mng:{0}({1})"; - - /** - * LOG FORMAT for the Subscription Log Subject - * 0 - Subscription ID - */ - public static final String SUBSCRIPTION_FORMAT = "sub:{0}"; - - /** - * LOG FORMAT for Connection Log Subject - SOCKET format - * 0 - Connection ID - * 1 - Remote Address - */ - public static final String SOCKET_FORMAT = "con:{0}({1})"; - - /** - * LOG FORMAT for Connection Log Subject - USER format - * 0 - Connection ID - * 1 - User ID - * 2 - IP - */ - public static final String USER_FORMAT = "con:{0}({1}@{2})"; - - /** - * LOG FORMAT for the Connection Log Subject - CON format - * 0 - Connection ID - * 1 - User ID - * 2 - IP - * 3 - Virtualhost - */ - public static final String CONNECTION_FORMAT = "con:{0}({1}@{2}/{3})"; - - /** - * LOG FORMAT for the Channel LogSubject - * 0 - Connection ID - * 1 - User ID - * 2 - IP - * 3 - Virtualhost - * 4 - Channel ID - */ - public static final String CHANNEL_FORMAT = CONNECTION_FORMAT + "/ch:{4}"; - - /** - * LOG FORMAT for the Exchange LogSubject, - * 0 - Virtualhost Name - * 1 - Exchange Type - * 2 - Exchange Name - */ - public static final String EXCHANGE_FORMAT = "vh(/{0})/ex({1}/{2})"; - - /** - * LOG FORMAT for a Binding LogSubject - * 0 - Virtualhost Name - * 1 - Exchange Type - * 2 - Exchange Name - * 3 - Queue Name - * 4 - Binding RoutingKey - */ - public static final String BINDING_FORMAT = "vh(/{0})/ex({1}/{2})/qu({3})/rk({4})"; - - /** - * LOG FORMAT for the MessagesStore LogSubject - * 0 - Virtualhost Name - * 1 - Message Store Type - */ - public static final String STORE_FORMAT = "vh(/{0})/ms({1})"; - - /** - * LOG FORMAT for the Queue LogSubject, - * 0 - Virtualhost name - * 1 - queue name - */ - public static final String QUEUE_FORMAT = "vh(/{0})/qu({1})"; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubject.java deleted file mode 100644 index ed989d764f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubject.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -import org.apache.qpid.server.virtualhost.VirtualHost; - -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.STORE_FORMAT; - -public class MessageStoreLogSubject extends AbstractLogSubject -{ - - /** Create an MessageStoreLogSubject that Logs in the following format. */ - public MessageStoreLogSubject(String vhostName, String messageStoreName) - { - setLogStringWithFormat(STORE_FORMAT, vhostName, messageStoreName); - } - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/QueueLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/QueueLogSubject.java deleted file mode 100644 index 53a9ab75d9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/QueueLogSubject.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -import org.apache.qpid.server.queue.AMQQueue; - -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.QUEUE_FORMAT; - -public class QueueLogSubject extends AbstractLogSubject -{ - - /** Create an QueueLogSubject that Logs in the following format. */ - public QueueLogSubject(AMQQueue queue) - { - setLogStringWithFormat(QUEUE_FORMAT, - queue.getVirtualHost().getName(), - queue.getName()); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubject.java deleted file mode 100644 index 9a23b733dc..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubject.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.logging.subjects; - -import org.apache.qpid.server.subscription.Subscription; - -import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.SUBSCRIPTION_FORMAT; - -import java.text.MessageFormat; - -public class SubscriptionLogSubject extends AbstractLogSubject -{ - - /** - * Create an QueueLogSubject that Logs in the following format. - * - * @param subscription - */ - public SubscriptionLogSubject(Subscription subscription) - { - // Delegate the formating of the Queue to the QueueLogSubject. So final - // log string format is: - // [ sub:<id>(vh(<vhost>)/qu(<queue>)) ] - - String queueString = new QueueLogSubject(subscription.getQueue()).toLogString(); - - setLogString("[" + MessageFormat.format(SUBSCRIPTION_FORMAT, - subscription.getSubscriptionID()) - + "(" - // queueString is [vh(/{0})/qu({1}) ] so need to trim - // ^ ^^ - + queueString.substring(1,queueString.length() - 3) - + ")" - + "] "); - - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AMQMessageHeader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AMQMessageHeader.java deleted file mode 100644 index 63bd1e45a0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AMQMessageHeader.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.message; - -import java.util.Collection; -import java.util.Set; - -public interface AMQMessageHeader -{ - String getCorrelationId(); - - long getExpiration(); - - String getUserId(); - - String getAppId(); - - String getMessageId(); - - String getMimeType(); - - String getEncoding(); - - byte getPriority(); - - long getTimestamp(); - - String getType(); - - String getReplyTo(); - - String getReplyToExchange(); - String getReplyToRoutingKey(); - - - Object getHeader(String name); - - boolean containsHeaders(Set<String> names); - - boolean containsHeader(String name); - - Collection<String> getHeaderNames(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AbstractServerMessageImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AbstractServerMessageImpl.java deleted file mode 100644 index 8311dbd5ff..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AbstractServerMessageImpl.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.message; - -import org.apache.qpid.server.store.StorableMessageMetaData; -import org.apache.qpid.server.store.StoredMessage; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -public abstract class AbstractServerMessageImpl<T extends StorableMessageMetaData> implements ServerMessage<T> -{ - - private static final AtomicIntegerFieldUpdater<AbstractServerMessageImpl> _refCountUpdater = - AtomicIntegerFieldUpdater.newUpdater(AbstractServerMessageImpl.class, "_referenceCount"); - - private volatile int _referenceCount = 0; - private final StoredMessage<T> _handle; - - public AbstractServerMessageImpl(StoredMessage<T> handle) - { - _handle = handle; - } - - public StoredMessage<T> getStoredMessage() - { - return _handle; - } - - public boolean incrementReference() - { - return incrementReference(1); - } - - public boolean incrementReference(int count) - { - if(_refCountUpdater.addAndGet(this, count) <= 0) - { - _refCountUpdater.addAndGet(this, -count); - return false; - } - else - { - return true; - } - } - - /** - * Threadsafe. This will decrement the reference count and when it reaches zero will remove the message from the - * message store. - * - */ - public void decrementReference() - { - int count = _refCountUpdater.decrementAndGet(this); - - // note that the operation of decrementing the reference count and then removing the message does not - // have to be atomic since the ref count starts at 1 and the exchange itself decrements that after - // the message has been passed to all queues. i.e. we are - // not relying on the all the increments having taken place before the delivery manager decrements. - if (count == 0) - { - // set the reference count way below 0 so that we can detect that the message has been deleted - // this is to guard against the message being spontaneously recreated (from the mgmt console) - // by copying from other queues at the same time as it is being removed. - _refCountUpdater.set(this,Integer.MIN_VALUE/2); - - // must check if the handle is null since there may be cases where we decide to throw away a message - // and the handle has not yet been constructed - if (_handle != null) - { - _handle.remove(); - } - } - else - { - if (count < 0) - { - throw new RuntimeException("Reference count for message id " + debugIdentity() - + " has gone below 0."); - } - } - } - - public String debugIdentity() - { - return "(HC:" + System.identityHashCode(this) + " ID:" + getMessageNumber() + " Ref:" + getReferenceCount() + ")"; - } - - protected int getReferenceCount() - { - return _referenceCount; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/EnqueableMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/EnqueableMessage.java deleted file mode 100755 index 7be91ad0ca..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/EnqueableMessage.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.message; - -import org.apache.qpid.server.store.StoredMessage; - -public interface EnqueableMessage -{ - long getMessageNumber(); - boolean isPersistent(); - StoredMessage getStoredMessage(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/InboundMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/InboundMessage.java deleted file mode 100644 index 1b3fdb1870..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/InboundMessage.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.message; - - -import org.apache.qpid.server.queue.Filterable; - -public interface InboundMessage extends Filterable -{ - String getRoutingKey(); - - AMQMessageHeader getMessageHeader(); - - boolean isPersistent(); - - boolean isRedelivered(); - - long getSize(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageContentSource.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageContentSource.java deleted file mode 100755 index 44741f57bd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageContentSource.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.message; - -import java.nio.ByteBuffer; - -public interface MessageContentSource -{ - public int getContent(ByteBuffer buf, int offset); - public ByteBuffer getContent(int offset, int size); - - long getSize(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageReference.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageReference.java deleted file mode 100644 index 399f8f9327..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageReference.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.message; - -import java.util.concurrent.atomic.AtomicBoolean; - -public abstract class MessageReference<M extends ServerMessage> -{ - - private final AtomicBoolean _released = new AtomicBoolean(false); - - private volatile M _message; - - public MessageReference(M message) - { - _message = message; - onReference(message); - } - - abstract protected void onReference(M message); - - abstract protected void onRelease(M message); - - public M getMessage() - { - return _message; - } - - public void release() - { - if(!_released.getAndSet(true)) - { - if(_message != null) - { - onRelease(_message); - } - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/ServerMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/ServerMessage.java deleted file mode 100644 index e1ad2fd0ca..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/ServerMessage.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.message; - -import org.apache.qpid.server.store.StorableMessageMetaData; -import org.apache.qpid.server.store.StoredMessage; - -import java.nio.ByteBuffer; - -public interface ServerMessage<T extends StorableMessageMetaData> extends EnqueableMessage, MessageContentSource -{ - String getRoutingKey(); - - AMQMessageHeader getMessageHeader(); - - public StoredMessage<T> getStoredMessage(); - - boolean isPersistent(); - - long getSize(); - - boolean isImmediate(); - - long getExpiration(); - - MessageReference newReference(); - - long getMessageNumber(); - - long getArrivalTime(); - - public int getContent(ByteBuffer buf, int offset); - - public ByteBuffer getContent(int offset, int size); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AccessControlProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AccessControlProvider.java deleted file mode 100644 index d96bef0463..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AccessControlProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import org.apache.qpid.server.security.AccessControl; - -public interface AccessControlProvider extends ConfiguredObject -{ - public static final String ID = "id"; - public static final String DESCRIPTION = "description"; - public static final String NAME = "name"; - public static final String STATE = "state"; - public static final String DURABLE = "durable"; - public static final String LIFETIME_POLICY = "lifetimePolicy"; - public static final String TIME_TO_LIVE = "timeToLive"; - public static final String CREATED = "created"; - public static final String UPDATED = "updated"; - public static final String TYPE = "type"; - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList(ID, - NAME, - DESCRIPTION, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - TYPE)); - - //retrieve the underlying AccessControl object - AccessControl getAccessControl(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Attribute.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Attribute.java deleted file mode 100644 index 4fccf47e0e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Attribute.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -public abstract class Attribute<C extends ConfiguredObject, T> -{ - private final String _name; - public Attribute(String name) - { - _name = name; - } - - public String getName() - { - return _name; - } - - abstract public Class<T> getType(); - - public T getValue(C configuredObject) - { - Object o = configuredObject.getAttribute(_name); - if(getType().isInstance(o)) - { - return (T) o; - } - return null; - } - - public T setValue(T expected, T desired, C configuredObject) - { - return (T) configuredObject.setAttribute(_name, expected, desired); - } - - abstract public T setValue(String stringValue, C configuredObject); - - static class StringAttribute<C extends ConfiguredObject> extends Attribute<C, String> - { - - public StringAttribute(String name) - { - super(name); - } - - @Override - public Class<String> getType() - { - return String.class; - } - - @Override - public String setValue(String stringValue, C configuredObject) - { - return setValue(getValue(configuredObject), stringValue, configuredObject); - } - - } - - static class IntegerAttribute<C extends ConfiguredObject> extends Attribute<C, Integer> - { - - public IntegerAttribute(String name) - { - super(name); - } - - @Override - public Class<Integer> getType() - { - return Integer.class; - } - - @Override - public Integer setValue(String stringValue, C configuredObject) - { - try - { - Integer val = Integer.valueOf(stringValue); - return setValue(getValue(configuredObject), val, configuredObject); - } - catch (NumberFormatException e) - { - throw new IllegalArgumentException(e); - } - } - } - - - static class LongAttribute<C extends ConfiguredObject> extends Attribute<C, Long> - { - - public LongAttribute(String name) - { - super(name); - } - - @Override - public Class<Long> getType() - { - return Long.class; - } - - @Override - public Long setValue(String stringValue, C configuredObject) - { - try - { - Long val = Long.valueOf(stringValue); - return setValue(getValue(configuredObject), val, configuredObject); - } - catch (NumberFormatException e) - { - throw new IllegalArgumentException(e); - } - } - } - - - static class DoubleAttribute<C extends ConfiguredObject> extends Attribute<C, Double> - { - - public DoubleAttribute(String name) - { - super(name); - } - - @Override - public Class<Double> getType() - { - return Double.class; - } - - @Override - public Double setValue(String stringValue, C configuredObject) - { - try - { - Double val = Double.valueOf(stringValue); - return setValue(getValue(configuredObject), val, configuredObject); - } - catch (NumberFormatException e) - { - throw new IllegalArgumentException(e); - } - } - } - - - static class FloatAttribute<C extends ConfiguredObject> extends Attribute<C, Float> - { - - public FloatAttribute(String name) - { - super(name); - } - - @Override - public Class<Float> getType() - { - return Float.class; - } - - @Override - public Float setValue(String stringValue, C configuredObject) - { - try - { - Float val = Float.valueOf(stringValue); - return setValue(getValue(configuredObject), val, configuredObject); - } - catch (NumberFormatException e) - { - throw new IllegalArgumentException(e); - } - } - } - - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationMethod.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationMethod.java deleted file mode 100644 index 7a5927a365..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationMethod.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Collection; - -public interface AuthenticationMethod extends ConfiguredObject -{ - // name is the SASL mech where this is a SASL authentication - - // parents - VirtualHostAlias getVirtualHostAlias(); - AuthenticationProvider getAuthenticationProvider(); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java deleted file mode 100644 index f75d0211cb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import org.apache.qpid.server.security.SubjectCreator; - -public interface AuthenticationProvider extends ConfiguredObject -{ - - public static final String ID = "id"; - public static final String DESCRIPTION = "description"; - public static final String NAME = "name"; - public static final String STATE = "state"; - public static final String DURABLE = "durable"; - public static final String LIFETIME_POLICY = "lifetimePolicy"; - public static final String TIME_TO_LIVE = "timeToLive"; - public static final String CREATED = "created"; - public static final String UPDATED = "updated"; - - public static final String TYPE = "type"; - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList(ID, - NAME, - DESCRIPTION, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - TYPE - )); - //children - Collection<VirtualHostAlias> getVirtualHostPortBindings(); - - String getName(); - - /** - * A temporary method to create SubjectCreator. - * - * TODO: move all the functionality from SubjectCreator into AuthenticationProvider - */ - SubjectCreator getSubjectCreator(); - - /** - * Returns the preferences provider associated with this authentication provider - * @return PreferencesProvider - */ - PreferencesProvider getPreferencesProvider(); - - /** - * Sets the preferences provider - * @param preferencesProvider - */ - void setPreferencesProvider(PreferencesProvider preferencesProvider); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Binding.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Binding.java deleted file mode 100644 index fdb009386c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Binding.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -public interface Binding extends ConfiguredObject -{ - - public String MATCHED_BYTES = "matchedBytes"; - public String MATCHED_MESSAGES = "matchedMessages"; - public String STATE_CHANGED = "stateChanged"; - - public static final Collection<String> AVAILABLE_STATISTICS = - Collections.unmodifiableCollection( - Arrays.asList( - MATCHED_BYTES, - MATCHED_MESSAGES, - STATE_CHANGED)); - - - public String ARGUMENTS = "arguments"; - public String CREATED = "created"; - public String DURABLE = "durable"; - public String ID = "id"; - public String LIFETIME_POLICY = "lifetimePolicy"; - public String NAME = "name"; - public String STATE = "state"; - public String TIME_TO_LIVE = "timeToLive"; - public String UPDATED = "updated"; - public String QUEUE = "queue"; - public String EXCHANGE = "exchange"; - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableCollection( - Arrays.asList(ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - EXCHANGE, - QUEUE, - ARGUMENTS) - ); - - - - Map<String,Object> getArguments(); - - void delete(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java deleted file mode 100644 index 0c1a6de58b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.net.SocketAddress; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import org.apache.qpid.server.logging.LogRecorder; -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.security.SubjectCreator; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; - -public interface Broker extends ConfiguredObject -{ - - String BUILD_VERSION = "buildVersion"; - String BYTES_RETAINED = "bytesRetained"; - String OPERATING_SYSTEM = "operatingSystem"; - String PLATFORM = "platform"; - String PROCESS_PID = "processPid"; - String PRODUCT_VERSION = "productVersion"; - String SUPPORTED_BROKER_STORE_TYPES = "supportedBrokerStoreTypes"; - String SUPPORTED_VIRTUALHOST_TYPES = "supportedVirtualHostTypes"; - String SUPPORTED_VIRTUALHOST_STORE_TYPES = "supportedVirtualHostStoreTypes"; - String SUPPORTED_AUTHENTICATION_PROVIDERS = "supportedAuthenticationProviders"; - String SUPPORTED_PREFERENCES_PROVIDERS_TYPES = "supportedPreferencesProviderTypes"; - String CREATED = "created"; - String DURABLE = "durable"; - String ID = "id"; - String LIFETIME_POLICY = "lifetimePolicy"; - String NAME = "name"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String UPDATED = "updated"; - String DEFAULT_VIRTUAL_HOST = "defaultVirtualHost"; - String STATISTICS_REPORTING_PERIOD = "statisticsReportingPeriod"; - String STATISTICS_REPORTING_RESET_ENABLED = "statisticsReportingResetEnabled"; - String STORE_TYPE = "storeType"; - String STORE_VERSION = "storeVersion"; - String STORE_PATH = "storePath"; - String MODEL_VERSION = "modelVersion"; - - String QUEUE_ALERT_THRESHOLD_MESSAGE_AGE = "queue.alertThresholdMessageAge"; - String QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES = "queue.alertThresholdQueueDepthMessages"; - String QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES = "queue.alertThresholdQueueDepthBytes"; - String QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE = "queue.alertThresholdMessageSize"; - String QUEUE_ALERT_REPEAT_GAP = "queue.alertRepeatGap"; - String QUEUE_FLOW_CONTROL_SIZE_BYTES = "queue.flowControlSizeBytes"; - String QUEUE_FLOW_CONTROL_RESUME_SIZE_BYTES = "queue.flowResumeSizeBytes"; - String QUEUE_MAXIMUM_DELIVERY_ATTEMPTS = "queue.maximumDeliveryAttempts"; - String QUEUE_DEAD_LETTER_QUEUE_ENABLED = "queue.deadLetterQueueEnabled"; - - String CONNECTION_SESSION_COUNT_LIMIT = "connection.sessionCountLimit"; - String CONNECTION_HEART_BEAT_DELAY = "connection.heartBeatDelay"; - String CONNECTION_CLOSE_WHEN_NO_ROUTE = "connection.closeWhenNoRoute"; - - String VIRTUALHOST_HOUSEKEEPING_CHECK_PERIOD = "virtualhost.housekeepingCheckPeriod"; - String VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE = "virtualhost.storeTransactionIdleTimeoutClose"; - String VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_WARN = "virtualhost.storeTransactionIdleTimeoutWarn"; - String VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE = "virtualhost.storeTransactionOpenTimeoutClose"; - String VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_WARN = "virtualhost.storeTransactionOpenTimeoutWarn"; - - // Attributes - Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList(BUILD_VERSION, - BYTES_RETAINED, - OPERATING_SYSTEM, - PLATFORM, - PROCESS_PID, - PRODUCT_VERSION, - SUPPORTED_BROKER_STORE_TYPES, - SUPPORTED_VIRTUALHOST_STORE_TYPES, - SUPPORTED_AUTHENTICATION_PROVIDERS, - SUPPORTED_PREFERENCES_PROVIDERS_TYPES, - CREATED, - DURABLE, - ID, - LIFETIME_POLICY, - NAME, - STATE, - TIME_TO_LIVE, - UPDATED, - DEFAULT_VIRTUAL_HOST, - QUEUE_ALERT_THRESHOLD_MESSAGE_AGE, - QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, - QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES, - QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE, - QUEUE_ALERT_REPEAT_GAP, - QUEUE_FLOW_CONTROL_SIZE_BYTES, - QUEUE_FLOW_CONTROL_RESUME_SIZE_BYTES, - QUEUE_MAXIMUM_DELIVERY_ATTEMPTS, - QUEUE_DEAD_LETTER_QUEUE_ENABLED, - VIRTUALHOST_HOUSEKEEPING_CHECK_PERIOD, - CONNECTION_SESSION_COUNT_LIMIT, - CONNECTION_HEART_BEAT_DELAY, - CONNECTION_CLOSE_WHEN_NO_ROUTE, - STATISTICS_REPORTING_PERIOD, - STATISTICS_REPORTING_RESET_ENABLED, - STORE_TYPE, - STORE_VERSION, - STORE_PATH, - MODEL_VERSION, - VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE, - VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_WARN, - VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE, - VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_WARN - )); - - //children - Collection < VirtualHost > getVirtualHosts(); - - Collection<Port> getPorts(); - - Collection<AuthenticationProvider> getAuthenticationProviders(); - - Collection<AccessControlProvider> getAccessControlProviders(); - - Collection<GroupProvider> getGroupProviders(); - - /** - * A temporary hack to expose root message logger via broker instance. - * TODO We need a better way to do operational logging, for example, via logging listeners - */ - RootMessageLogger getRootMessageLogger(); - - /** - * A temporary hack to expose security manager via broker instance. - * TODO We need to add and implement an authorization provider configured object instead - */ - SecurityManager getSecurityManager(); - - /** - * TODO: A temporary hack to expose log recorder via broker instance. - */ - LogRecorder getLogRecorder(); - - AuthenticationProvider findAuthenticationProviderByName(String authenticationProviderName); - - VirtualHost findVirtualHostByName(String name); - - KeyStore findKeyStoreByName(String name); - - TrustStore findTrustStoreByName(String name); - - /** - * Get the SubjectCreator for the given socket address. - * TODO: move the authentication related functionality into host aliases and AuthenticationProviders - * - * @param address The (listening) socket address for which the AuthenticationManager is required - */ - SubjectCreator getSubjectCreator(SocketAddress localAddress); - - Collection<KeyStore> getKeyStores(); - - Collection<TrustStore> getTrustStores(); - - /* - * TODO: Remove this method. Eventually the broker will become a registry. - */ - VirtualHostRegistry getVirtualHostRegistry(); - - TaskExecutor getTaskExecutor(); - - boolean isManagementMode(); - - AuthenticationProvider getAuthenticationProvider(SocketAddress localAddress); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java deleted file mode 100644 index d20c709e90..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -public interface ConfigurationChangeListener -{ - /** - * Inform the listener that the passed object has changed state - * - * @param object the object whose state has changed - * @param oldState the state prior to the change - * @param newState the state after the change - */ - void stateChanged(ConfiguredObject object, State oldState, State newState); - - void childAdded(ConfiguredObject object, ConfiguredObject child); - - void childRemoved(ConfiguredObject object, ConfiguredObject child); - - void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java deleted file mode 100644 index 45e743dbca..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.security.AccessControlException; -import java.util.Collection; -import java.util.Map; -import java.util.UUID; - -/** - * An object that can be "managed" (eg via the web interface) and usually read from configuration. - */ -public interface ConfiguredObject -{ - - /** - * Get the universally unique identifier for the object - * - * @return the objects id - */ - UUID getId(); - - /** - * Get the name of the object - * - * @return the name of the object - */ - String getName(); - - - /** - * Attempt to change the name of the object - * - * Request a change to the name of the object. The caller must pass in the name it believes the object currently - * has. If the current name differs from this expected value, then no name change will occur - * - * @param currentName the name the caller believes the object to have - * @param desiredName the name the caller would like the object to have - * @return the new name for the object - * @throws IllegalStateException if the name of the object may not be changed in in the current state - * @throws AccessControlException if the current context does not have permission to change the name - * @throws IllegalArgumentException if the provided name is not legal - * @throws NullPointerException if the desired name is null - */ - String setName(String currentName, String desiredName) throws IllegalStateException, - AccessControlException; - - - /** - * Get the desired state of the object. - * - * This is the state set at the object itself, however the object - * may not be able attain this state if one of its ancestors is in a different state (in particular a descendant - * object may not be ACTIVE if all of its ancestors are not also ACTIVE). - * - * @return the desired state of the object - */ - State getDesiredState(); - - /** - * Change the desired state of the object - * - * Request a change to the current state. The caller must pass in the state it believe the object to be in, if - * this differs from the current desired state when the object evalues the request, then no state change will occur. - * - * @param currentState the state the caller believes the object to be in - * @param desiredState the state the caller wishes the object to attain - * @return the new current state - * @throws IllegalStateTransitionException the requested state tranisition is invalid - * @throws AccessControlException the current context does not have sufficient permissions to change the state - */ - State setDesiredState(State currentState, State desiredState) throws IllegalStateTransitionException, - AccessControlException; - - /** - * Get the actual state of the object. - * - * This state is derived from the desired state of the object itself and - * the actual state of its parents. If an object "desires" to be ACTIVE, but one of its parents is STOPPED, then - * the actual state of the object will be STOPPED - * - * @return the actual state of the object - */ - State getActualState(); - - - /** - * Add a listener which will be informed of all changes to this configuration object - * - * @param listener the listener to add - */ - void addChangeListener(ConfigurationChangeListener listener); - - /** - * Remove a change listener - * - * - * @param listener the listener to remove - * @return true iff a listener was removed - */ - boolean removeChangeListener(ConfigurationChangeListener listener); - - /** - * Get the parent of the given type for this object - * - * @param clazz the class of parent being asked for - * @return the objects parent - */ - <T extends ConfiguredObject> T getParent(Class<T> clazz); - - - /** - * Returns whether the the object configuration is durably stored - * - * @return the durability - */ - boolean isDurable(); - - /** - * Sets the durability of the object - * - * @param durable true iff the caller wishes the object to store its configuration durably - * - * @throws IllegalStateException if the durability cannot be changed in the current state - * @throws AccessControlException if the current context does not have sufficient permission to change the durability - * @throws IllegalArgumentException if the object does not support the requested durability - */ - void setDurable(boolean durable) throws IllegalStateException, - AccessControlException, - IllegalArgumentException; - - /** - * Return the lifetime policy for the object - * - * @return the lifetime policy - */ - LifetimePolicy getLifetimePolicy(); - - /** - * Set the lifetime policy of the object - * - * @param expected The lifetime policy the caller believes the object currently has - * @param desired The lifetime policy the caller desires the object to have - * @return the new lifetime policy - * @throws IllegalStateException if the lifetime policy cannot be changed in the current state - * @throws AccessControlException if the caller does not have permission to change the lifetime policy - * @throws IllegalArgumentException if the object does not support the requested lifetime policy - */ - LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) throws IllegalStateException, - AccessControlException, - IllegalArgumentException; - - /** - * Get the time the object will live once the lifetime policy conditions are no longer fulfilled - * - * @return the time to live - */ - long getTimeToLive(); - - /** - * Set the ttl value - * - * @param expected the ttl the caller believes the object currently has - * @param desired the ttl value the caller - * @return the new ttl value - * @throws IllegalStateException if the ttl cannot be set in the current state - * @throws AccessControlException if the caller does not have permission to change the ttl - * @throws IllegalArgumentException if the object does not support the requested ttl value - */ - long setTimeToLive(long expected, long desired) throws IllegalStateException, - AccessControlException, - IllegalArgumentException; - - /** - * Get the names of attributes that are set on this object - * - * Note that the returned collection is correct at the time the method is called, but will not reflect future - * additions or removals when they occur - * - * @return the collection of attribute names - */ - Collection<String> getAttributeNames(); - - - /** - * Return the value for the given attribute name. The actual attribute value - * is returned if the configured object has such attribute set. If not, the - * value is looked default attributes. - * - * @param name - * the name of the attribute - * @return the value of the attribute at the object (or null if the - * attribute value is set neither on object itself no in defaults) - */ - Object getAttribute(String name); - - /** - * Return the map containing only explicitly set attributes - * - * @return the map with the attributes - */ - Map<String, Object> getActualAttributes(); - - /** - * Set the value of an attribute - * - * @param name the name of the attribute to be set - * @param expected the value the caller believes the attribute currently has (or null if it is expected to be unset) - * @param desired the desired value for the attribute (or null to unset the attribute) - * @return the new value for the given attribute - * @throws IllegalStateException if the attribute cannot be set while the object is in its current state - * @throws AccessControlException if the caller does not have permission to alter the value of the attribute - * @throws IllegalArgumentException if the provided value is not valid for the given argument - */ - Object setAttribute(String name, Object expected, Object desired) throws IllegalStateException, - AccessControlException, - IllegalArgumentException; - - - /** - * Return the Statistics holder for the ConfiguredObject - * - * @return the Statistics holder for the ConfiguredObject (or null if none exists) - */ - Statistics getStatistics(); - - /** - * Return children of the ConfiguredObject of the given class - * - * @param clazz the class of the children to return - * @return the children - * - * @throws NullPointerException if the supplied class null - * - */ - <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz); - - - <C extends ConfiguredObject> C createChild(Class<C> childClass, - Map<String, Object> attributes, - ConfiguredObject... otherParents); - - void setAttributes(Map<String, Object> attributes) throws IllegalStateException, AccessControlException, IllegalArgumentException; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFinder.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFinder.java deleted file mode 100644 index 6a7d6f8f7b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFinder.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Collection; - -public class ConfiguredObjectFinder -{ - public static <C extends ConfiguredObject> C findConfiguredObjectByName(Collection<C> configuredObjects, String name) - { - for (C configuredObject : configuredObjects) - { - if (name.equals(configuredObject.getName())) - { - return configuredObject; - } - } - return null; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Connection.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Connection.java deleted file mode 100644 index 3139850892..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Connection.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -public interface Connection extends ConfiguredObject -{ - - // Statistics - - String BYTES_IN = "bytesIn"; - String BYTES_OUT = "bytesOut"; - String LAST_IO_TIME = "lastIoTime"; - String LOCAL_TRANSACTION_BEGINS = "localTransactionBegins"; - String LOCAL_TRANSACTION_ROLLBACKS = "localTransactionRollbacks"; - String MESSAGES_IN = "messagesIn"; - String MESSAGES_OUT = "messagesOut"; - String SESSION_COUNT = "sessionCount"; - String STATE_CHANGED = "stateChanged"; - String XA_TRANSACTION_BRANCH_ENDS = "xaTransactionBranchEnds"; - String XA_TRANSACTION_BRANCH_STARTS = "xaTransactionBranchStarts"; - String XA_TRANSACTION_BRANCH_SUSPENDS = "xaTransactionBranchSuspends"; - - public static final Collection<String> AVAILABLE_STATISTICS = - Collections.unmodifiableCollection( - Arrays.asList(BYTES_IN, - BYTES_OUT, - LAST_IO_TIME, - LOCAL_TRANSACTION_BEGINS, - LOCAL_TRANSACTION_ROLLBACKS, - MESSAGES_IN, - MESSAGES_OUT, - SESSION_COUNT, - STATE_CHANGED, - XA_TRANSACTION_BRANCH_ENDS, - XA_TRANSACTION_BRANCH_STARTS, - XA_TRANSACTION_BRANCH_SUSPENDS)); - - // Attributes - - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String STATE = "state"; - public static final String DURABLE = "durable"; - public static final String LIFETIME_POLICY = "lifetimePolicy"; - public static final String TIME_TO_LIVE = "timeToLive"; - public static final String CREATED = "created"; - public static final String UPDATED = "updated"; - - public static final String CLIENT_ID = "clientId"; - public static final String CLIENT_VERSION = "clientVersion"; - public static final String INCOMING = "incoming"; - public static final String LOCAL_ADDRESS = "localAddress"; - public static final String PRINCIPAL = "principal"; - public static final String PROPERTIES = "properties"; - public static final String REMOTE_ADDRESS = "remoteAddress"; - public static final String REMOTE_PROCESS_NAME = "remoteProcessName"; - public static final String REMOTE_PROCESS_PID = "remoteProcessPid"; - public static final String SESSION_COUNT_LIMIT = "sessionCountLimit"; - public static final String TRANSPORT = "transport"; - public static final String PORT = "port"; - - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableCollection( - Arrays.asList( ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - CLIENT_ID, - CLIENT_VERSION, - INCOMING, - LOCAL_ADDRESS, - PRINCIPAL, - PROPERTIES, - REMOTE_ADDRESS, - REMOTE_PROCESS_NAME, - REMOTE_PROCESS_PID, - SESSION_COUNT_LIMIT, - TRANSPORT, - PORT)); - - //children - Collection<Session> getSessions(); - - void delete(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Consumer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Consumer.java deleted file mode 100644 index 958177e713..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Consumer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -public interface Consumer extends ConfiguredObject -{ - public String DISTRIBUTION_MODE = "distributionMode"; - public String EXCLUSIVE = "exclusive"; - public String NO_LOCAL = "noLocal"; - public String SELECTOR = "selector"; - public String SETTLEMENT_MODE = "settlementMode"; - public String CREATED = "created"; - public String DURABLE = "durable"; - public String ID = "id"; - public String LIFETIME_POLICY = "lifetimePolicy"; - public String NAME = "name"; - public String STATE = "state"; - public String TIME_TO_LIVE = "timeToLive"; - public String UPDATED = "updated"; - - public Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableCollection( - Arrays.asList(ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - DISTRIBUTION_MODE, - SETTLEMENT_MODE, - EXCLUSIVE, - NO_LOCAL, - SELECTOR)); - - public String BYTES_OUT = "bytesOut"; - public String MESSAGES_OUT = "messagesOut"; - public String STATE_CHANGED = "stateChanged"; - public String UNACKNOWLEDGED_BYTES = "unacknowledgedBytes"; - public String UNACKNOWLEDGED_MESSAGES = "unacknowledgedMessages"; - - public Collection<String> AVAILABLE_STATISTICS = - Collections.unmodifiableCollection( - Arrays.asList(BYTES_OUT, - MESSAGES_OUT, - STATE_CHANGED, - UNACKNOWLEDGED_BYTES, - UNACKNOWLEDGED_MESSAGES) - ); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Event.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Event.java deleted file mode 100644 index 91b684f06e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Event.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -abstract public class Event<T extends EventType> -{ - abstract public T getEventType(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/EventType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/EventType.java deleted file mode 100644 index edd5ce4250..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/EventType.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.HashMap; -import java.util.Map; - -/** - * A type of event generated by a ConfiguredObject. - */ -public abstract class EventType<T extends EventType<T>> -{ - private static final Map<Class<? extends EventType>, Integer> EVENT_TYPES = - new HashMap<Class<? extends EventType>, Integer>(); - - private final int _classId; - - protected EventType() - { - synchronized (EVENT_TYPES) - { - if(EVENT_TYPES.containsKey(getClass())) - { - throw new IllegalArgumentException("Cannot define more one instance of the same EventType " + - getClass().getName()); - } - else - { - _classId = EVENT_TYPES.size(); - EVENT_TYPES.put(getClass(), _classId); - } - } - } - - public final int getId() - { - return _classId; - } - - abstract public Event<T> newEvent(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Exchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Exchange.java deleted file mode 100644 index e63c71e955..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Exchange.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -public interface Exchange extends ConfiguredObject -{ - String BINDING_COUNT = "bindingCount"; - String BYTES_DROPPED = "bytesDropped"; - String BYTES_IN = "bytesIn"; - String MESSAGES_DROPPED = "messagesDropped"; - String MESSAGES_IN = "messagesIn"; - String PRODUCER_COUNT = "producerCount"; - String STATE_CHANGED = "stateChanged"; - - public static final Collection<String> AVAILABLE_STATISTICS = - Collections.unmodifiableList( - Arrays.asList(BINDING_COUNT, - BYTES_DROPPED, - BYTES_IN, - MESSAGES_DROPPED, - MESSAGES_IN, - PRODUCER_COUNT, - STATE_CHANGED)); - - String CREATED = "created"; - String DURABLE = "durable"; - String ID = "id"; - String LIFETIME_POLICY = "lifetimePolicy"; - String NAME = "name"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String UPDATED = "updated"; - String ALTERNATE_EXCHANGE = "alternateExchange"; - String TYPE = "type"; - - // Attributes - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - ALTERNATE_EXCHANGE, - TYPE - )); - - String getExchangeType(); - - //children - Collection<Binding> getBindings(); - Collection<Publisher> getPublishers(); - - //operations - Binding createBinding(String bindingKey, - Queue queue, - Map<String,Object> bindingArguments, - Map<String, Object> attributes); - - - // Statistics - - void delete(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Group.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Group.java deleted file mode 100644 index aacd515107..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Group.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -public interface Group extends ConfiguredObject -{ - String CREATED = "created"; - String DURABLE = "durable"; - String ID = "id"; - String LIFETIME_POLICY = "lifetimePolicy"; - String NAME = "name"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String UPDATED = "updated"; - - // Attributes - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED - )); - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupMember.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupMember.java deleted file mode 100644 index 6832cc6fa6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupMember.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -public interface GroupMember extends ConfiguredObject -{ - String CREATED = "created"; - String DURABLE = "durable"; - String ID = "id"; - String LIFETIME_POLICY = "lifetimePolicy"; - String NAME = "name"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String UPDATED = "updated"; - - // Attributes - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED - )); - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java deleted file mode 100644 index 9016f97927..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.security.Principal; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -public interface GroupProvider extends ConfiguredObject -{ - public static final String ID = "id"; - public static final String DESCRIPTION = "description"; - public static final String NAME = "name"; - public static final String STATE = "state"; - public static final String DURABLE = "durable"; - public static final String LIFETIME_POLICY = "lifetimePolicy"; - public static final String TIME_TO_LIVE = "timeToLive"; - public static final String CREATED = "created"; - public static final String UPDATED = "updated"; - public static final String TYPE = "type"; - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList(ID, - NAME, - DESCRIPTION, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - TYPE)); - - Set<Principal> getGroupPrincipalsForUser(String username); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/IllegalStateTransitionException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/IllegalStateTransitionException.java deleted file mode 100644 index 9cab5e2103..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/IllegalStateTransitionException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -public class IllegalStateTransitionException extends RuntimeException -{ - public IllegalStateTransitionException() - { - } - - public IllegalStateTransitionException(final String message) - { - super(message); - } - - public IllegalStateTransitionException(final String message, final Throwable cause) - { - super(message, cause); - } - - public IllegalStateTransitionException(final Throwable cause) - { - super(cause); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/IntegrityViolationException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/IntegrityViolationException.java deleted file mode 100644 index def450640a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/IntegrityViolationException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -public class IntegrityViolationException extends RuntimeException -{ - private static final long serialVersionUID = 1L; - - public IntegrityViolationException(String message, Throwable cause) - { - super(message, cause); - } - - public IntegrityViolationException(String message) - { - super(message); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java deleted file mode 100644 index ab909390bd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.security.GeneralSecurityException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import javax.net.ssl.KeyManager; - -public interface KeyStore extends ConfiguredObject -{ - String ID = "id"; - String NAME = "name"; - String DURABLE = "durable"; - String LIFETIME_POLICY = "lifetimePolicy"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String CREATED = "created"; - String UPDATED = "updated"; - String DESCRIPTION = "description"; - - String PATH = "path"; - String PASSWORD = "password"; - String TYPE = "type"; - String CERTIFICATE_ALIAS = "certificateAlias"; - String KEY_MANAGER_FACTORY_ALGORITHM = "keyManagerFactoryAlgorithm"; - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - DESCRIPTION, - PATH, - PASSWORD, - TYPE, - CERTIFICATE_ALIAS, - KEY_MANAGER_FACTORY_ALGORITHM - )); - - public String getPassword(); - - public void setPassword(String password); - - public KeyManager[] getKeyManagers() throws GeneralSecurityException; - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/LifetimePolicy.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/LifetimePolicy.java deleted file mode 100644 index c9006f4e71..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/LifetimePolicy.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -public enum LifetimePolicy -{ - PERMANENT, - AUTO_DELETE -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java deleted file mode 100644 index 45fadbdbcb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class Model -{ - /* - * API version for the broker model - * - * 1.0 Initial version - * 1.1 Addition of mandatory virtual host type / different types of virtual host - * - */ - public static final int MODEL_MAJOR_VERSION = 1; - public static final int MODEL_MINOR_VERSION = 1; - public static final String MODEL_VERSION = MODEL_MAJOR_VERSION + "." + MODEL_MINOR_VERSION; - - private static final Model MODEL_INSTANCE = new Model(); - - private final Map<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>> - _parents = new HashMap<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>>(); - - private final Map<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>> - _children = new HashMap<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>>(); - - public static Model getInstance() - { - return MODEL_INSTANCE; - } - - private Model() - { - addRelationship(Broker.class, VirtualHost.class); - addRelationship(Broker.class, Port.class); - addRelationship(Broker.class, AccessControlProvider.class); - addRelationship(Broker.class, AuthenticationProvider.class); - addRelationship(Broker.class, GroupProvider.class); - addRelationship(Broker.class, TrustStore.class); - addRelationship(Broker.class, KeyStore.class); - addRelationship(Broker.class, Plugin.class); - - addRelationship(VirtualHost.class, Exchange.class); - addRelationship(VirtualHost.class, Queue.class); - addRelationship(VirtualHost.class, Connection.class); - addRelationship(VirtualHost.class, VirtualHostAlias.class); - - addRelationship(AuthenticationProvider.class, User.class); - addRelationship(AuthenticationProvider.class, PreferencesProvider.class); - addRelationship(User.class, GroupMember.class); - - addRelationship(GroupProvider.class, Group.class); - addRelationship(Group.class, GroupMember.class); - - addRelationship(Connection.class, Session.class); - - addRelationship(Queue.class, Binding.class); - addRelationship(Queue.class, Consumer.class); - - addRelationship(Exchange.class, Binding.class); - addRelationship(Exchange.class, Publisher.class); - - addRelationship(Session.class, Consumer.class); - addRelationship(Session.class, Publisher.class); - } - - public Collection<Class<? extends ConfiguredObject>> getParentTypes(Class<? extends ConfiguredObject> child) - { - Collection<Class<? extends ConfiguredObject>> parentTypes = _parents.get(child); - return parentTypes == null ? Collections.<Class<? extends ConfiguredObject>>emptyList() - : Collections.unmodifiableCollection(parentTypes); - } - - public Collection<Class<? extends ConfiguredObject>> getChildTypes(Class<? extends ConfiguredObject> parent) - { - Collection<Class<? extends ConfiguredObject>> childTypes = _children.get(parent); - return childTypes == null ? Collections.<Class<? extends ConfiguredObject>>emptyList() - : Collections.unmodifiableCollection(childTypes); - } - - private void addRelationship(Class<? extends ConfiguredObject> parent, Class<? extends ConfiguredObject> child) - { - Collection<Class<? extends ConfiguredObject>> parents = _parents.get(child); - if(parents == null) - { - parents = new ArrayList<Class<? extends ConfiguredObject>>(); - _parents.put(child, parents); - } - parents.add(parent); - - Collection<Class<? extends ConfiguredObject>> children = _children.get(parent); - if(children == null) - { - children = new ArrayList<Class<? extends ConfiguredObject>>(); - _children.put(parent, children); - } - children.add(child); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/PasswordCredentialManagingAuthenticationProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/PasswordCredentialManagingAuthenticationProvider.java deleted file mode 100644 index 1027e5ce8c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/PasswordCredentialManagingAuthenticationProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.io.IOException; -import java.util.Map; - -import javax.security.auth.login.AccountNotFoundException; - -public interface PasswordCredentialManagingAuthenticationProvider extends AuthenticationProvider -{ - boolean createUser(String username, String password, Map<String, String> attributes); - - void deleteUser(String user) throws AccountNotFoundException; - - void setPassword(String username, String password) throws AccountNotFoundException; - - Map<String, Map<String,String>> getUsers(); - - /** - * Refreshes the cache of user and password data from the underlying storage. - * - * If there is a failure whilst reloading the data, the implementation must - * throw an {@link IOException} and revert to using the previous cached username - * and password data. In this way, the broker will remain usable. - */ - void reload() throws IOException; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java deleted file mode 100644 index b9503a5841..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -public interface Plugin extends ConfiguredObject -{ - //Hack, using it for the class name only for consistency with the other things. - String CREATED = "created"; - String DURABLE = "durable"; - String ID = "id"; - String LIFETIME_POLICY = "lifetimePolicy"; - String NAME = "name"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String UPDATED = "updated"; - - // Attributes - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED - )); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java deleted file mode 100644 index 60d62e3f27..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.security.AccessControlException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -public interface Port extends ConfiguredObject -{ - String CREATED = "created"; - String DURABLE = "durable"; - String ID = "id"; - String LIFETIME_POLICY = "lifetimePolicy"; - String NAME = "name"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String UPDATED = "updated"; - String BINDING_ADDRESS = "bindingAddress"; - String PORT = "port"; - String PROTOCOLS = "protocols"; - String TRANSPORTS = "transports"; - String TCP_NO_DELAY = "tcpNoDelay"; - String SEND_BUFFER_SIZE = "sendBufferSize"; - String RECEIVE_BUFFER_SIZE = "receiveBufferSize"; - String NEED_CLIENT_AUTH = "needClientAuth"; - String WANT_CLIENT_AUTH = "wantClientAuth"; - String AUTHENTICATION_PROVIDER = "authenticationProvider"; - String KEY_STORE = "keyStore"; - String TRUST_STORES = "trustStores"; - - // Attributes - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - BINDING_ADDRESS, - PORT, - PROTOCOLS, - TRANSPORTS, - TCP_NO_DELAY, - SEND_BUFFER_SIZE, - RECEIVE_BUFFER_SIZE, - NEED_CLIENT_AUTH, - WANT_CLIENT_AUTH, - AUTHENTICATION_PROVIDER, - KEY_STORE, - TRUST_STORES - )); - - - String getBindingAddress(); - - int getPort(); - - KeyStore getKeyStore(); - - Collection<TrustStore> getTrustStores(); - - Collection<Transport> getTransports(); - - void addTransport(Transport transport) throws IllegalStateException, - AccessControlException, - IllegalArgumentException; - - Transport removeTransport(Transport transport) throws IllegalStateException, - AccessControlException, - IllegalArgumentException; - - Collection<Protocol> getProtocols(); - - void addProtocol(Protocol protocol) throws IllegalStateException, - AccessControlException, - IllegalArgumentException; - - Protocol removeProtocol(Protocol protocol) throws IllegalStateException, - AccessControlException, - IllegalArgumentException; - - AuthenticationProvider getAuthenticationProvider(); - - //children - Collection<VirtualHostAlias> getVirtualHostBindings(); - Collection<Connection> getConnections(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/PreferencesProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/PreferencesProvider.java deleted file mode 100644 index 96d02b2ef6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/PreferencesProvider.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -public interface PreferencesProvider extends ConfiguredObject -{ - String ID = "id"; - String NAME = "name"; - String TYPE = "type"; - String CREATED = "created"; - String UPDATED = "updated"; - String DURABLE = "durable"; - String LIFETIME_POLICY = "lifetimePolicy"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - - Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - TYPE, - CREATED, - UPDATED, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE - )); - - /** - * Returns preferences {@link Map} for a given user ID - * @param userId user ID to retrieve preferences for - * @return preferences {@link Map} - */ - Map<String, Object> getPreferences(String userId); - - /** - * Set user preferences as specified in a given {@link Map} - * @param userId user ID to set preferences for - * @param preferences new preferences - * @return existing user preferences - */ - Map<String, Object> setPreferences(String userId, Map<String, Object> preferences); - - /** - * Delete preferences for a given user ID - * @param userId user ID to delete preferences for - * @return user preferences before the deletion - */ - Map<String, Object> deletePreferences(String userId); - - /** - * Returns set of the user IDs having preferences set - * @return user IDs - */ - Set<String> listUserIDs(); - - /** - * Returns authentication provider associated with this preferences provider - * @return authentication provider - */ - AuthenticationProvider getAuthenticationProvider(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java deleted file mode 100644 index e9d50fbc59..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Collection; -import java.util.EnumSet; - -import org.apache.qpid.server.protocol.AmqpProtocolVersion; - -public enum Protocol -{ - AMQP_0_8(ProtocolType.AMQP), - AMQP_0_9(ProtocolType.AMQP), - AMQP_0_9_1(ProtocolType.AMQP), - AMQP_0_10(ProtocolType.AMQP), - AMQP_1_0(ProtocolType.AMQP), - JMX_RMI(ProtocolType.JMX), - HTTP(ProtocolType.HTTP), - RMI(ProtocolType.RMI); - - private final ProtocolType _protocolType; - - private Protocol(ProtocolType type) - { - _protocolType = type; - } - - public ProtocolType getProtocolType() - { - return _protocolType; - } - - public boolean isAMQP() - { - return _protocolType == ProtocolType.AMQP; - } - - public AmqpProtocolVersion toAmqpProtocolVersion() - { - switch(this) - { - case AMQP_0_8: - return AmqpProtocolVersion.v0_8; - case AMQP_0_9: - return AmqpProtocolVersion.v0_9; - case AMQP_0_9_1: - return AmqpProtocolVersion.v0_9_1; - case AMQP_0_10: - return AmqpProtocolVersion.v0_10; - case AMQP_1_0: - return AmqpProtocolVersion.v1_0_0; - default: - throw new IllegalArgumentException(this + " is not an known AMQP protocol"); - } - } - - public static Protocol valueOfObject(Object protocolObject) - { - Protocol protocol; - if (protocolObject instanceof Protocol) - { - protocol = (Protocol) protocolObject; - } - else - { - try - { - protocol = Protocol.valueOf(String.valueOf(protocolObject)); - } - catch (Exception e) - { - throw new IllegalArgumentException("Can't convert '" + protocolObject - + "' to one of the supported protocols: " + EnumSet.allOf(Protocol.class), e); - } - } - return protocol; - } - - public static boolean hasAmqpProtocol(Collection<Protocol> protocols) - { - for (Protocol protocol : protocols) - { - if (protocol.isAMQP()) - { - return true; - } - } - return false; - } - - public static enum ProtocolType - { - AMQP, HTTP, JMX, RMI; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Publisher.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Publisher.java deleted file mode 100644 index cdb85d8023..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Publisher.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -public interface Publisher extends ConfiguredObject -{ -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Queue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Queue.java deleted file mode 100644 index ae2031bd71..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Queue.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import org.apache.qpid.server.queue.QueueEntryVisitor; - -public interface Queue extends ConfiguredObject -{ - public static final String BINDING_COUNT = "bindingCount"; - public static final String CONSUMER_COUNT = "consumerCount"; - public static final String CONSUMER_COUNT_WITH_CREDIT = "consumerCountWithCredit"; - public static final String DISCARDS_TTL_BYTES = "discardsTtlBytes"; - public static final String DISCARDS_TTL_MESSAGES = "discardsTtlMessages"; - public static final String PERSISTENT_DEQUEUED_BYTES = "persistentDequeuedBytes"; - public static final String PERSISTENT_DEQUEUED_MESSAGES = "persistentDequeuedMessages"; - public static final String PERSISTENT_ENQUEUED_BYTES = "persistentEnqueuedBytes"; - public static final String PERSISTENT_ENQUEUED_MESSAGES = "persistentEnqueuedMessages"; - public static final String QUEUE_DEPTH_BYTES = "queueDepthBytes"; - public static final String QUEUE_DEPTH_MESSAGES = "queueDepthMessages"; - public static final String STATE_CHANGED = "stateChanged"; - public static final String TOTAL_DEQUEUED_BYTES = "totalDequeuedBytes"; - public static final String TOTAL_DEQUEUED_MESSAGES = "totalDequeuedMessages"; - public static final String TOTAL_ENQUEUED_BYTES = "totalEnqueuedBytes"; - public static final String TOTAL_ENQUEUED_MESSAGES = "totalEnqueuedMessages"; - public static final String UNACKNOWLEDGED_BYTES = "unacknowledgedBytes"; - public static final String UNACKNOWLEDGED_MESSAGES = "unacknowledgedMessages"; - - public static final Collection<String> AVAILABLE_STATISTICS = - Collections.unmodifiableList( - Arrays.asList(BINDING_COUNT, - CONSUMER_COUNT, - CONSUMER_COUNT_WITH_CREDIT, - DISCARDS_TTL_BYTES, - DISCARDS_TTL_MESSAGES, - PERSISTENT_DEQUEUED_BYTES, - PERSISTENT_DEQUEUED_MESSAGES, - PERSISTENT_ENQUEUED_BYTES, - PERSISTENT_ENQUEUED_MESSAGES, - QUEUE_DEPTH_BYTES, - QUEUE_DEPTH_MESSAGES, - STATE_CHANGED, - TOTAL_DEQUEUED_BYTES, - TOTAL_DEQUEUED_MESSAGES, - TOTAL_ENQUEUED_BYTES, - TOTAL_ENQUEUED_MESSAGES, - UNACKNOWLEDGED_BYTES, - UNACKNOWLEDGED_MESSAGES)); - - - - public static final String ID = "id"; - public static final String DESCRIPTION = "description"; - public static final String NAME = "name"; - public static final String STATE = "state"; - public static final String DURABLE = "durable"; - public static final String LIFETIME_POLICY = "lifetimePolicy"; - public static final String TIME_TO_LIVE = "timeToLive"; - public static final String CREATED = "created"; - public static final String UPDATED = "updated"; - public static final String ARGUMENTS = "arguments"; - - public static final String ALERT_REPEAT_GAP = "alertRepeatGap"; - public static final String ALERT_THRESHOLD_MESSAGE_AGE = "alertThresholdMessageAge"; - public static final String ALERT_THRESHOLD_MESSAGE_SIZE = "alertThresholdMessageSize"; - public static final String ALERT_THRESHOLD_QUEUE_DEPTH_BYTES = "alertThresholdQueueDepthBytes"; - public static final String ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES = "alertThresholdQueueDepthMessages"; - public static final String ALTERNATE_EXCHANGE = "alternateExchange"; - public static final String EXCLUSIVE = "exclusive"; - public static final String MESSAGE_GROUP_KEY = "messageGroupKey"; - public static final String MESSAGE_GROUP_SHARED_GROUPS = "messageGroupSharedGroups"; - public static final String MESSAGE_GROUP_DEFAULT_GROUP = "messageGroupDefaultGroup"; - public static final String LVQ_KEY = "lvqKey"; - public static final String MAXIMUM_DELIVERY_ATTEMPTS = "maximumDeliveryAttempts"; - public static final String NO_LOCAL = "noLocal"; - public static final String OWNER = "owner"; - public static final String QUEUE_FLOW_CONTROL_SIZE_BYTES = "queueFlowControlSizeBytes"; - public static final String QUEUE_FLOW_RESUME_SIZE_BYTES = "queueFlowResumeSizeBytes"; - public static final String QUEUE_FLOW_STOPPED = "queueFlowStopped"; - public static final String SORT_KEY = "sortKey"; - public static final String TYPE = "type"; - public static final String PRIORITIES = "priorities"; - - public static final String CREATE_DLQ_ON_CREATION = "x-qpid-dlq-enabled"; // TODO - this value should change - - public static final String FEDERATION_EXCLUDES = "federationExcludes"; - public static final String FEDERATION_ID = "federationId"; - - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList(ID, - NAME, - DESCRIPTION, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - TYPE, - ALTERNATE_EXCHANGE, - EXCLUSIVE, - OWNER, - NO_LOCAL, - LVQ_KEY, - SORT_KEY, - MESSAGE_GROUP_KEY, - MESSAGE_GROUP_SHARED_GROUPS, - MAXIMUM_DELIVERY_ATTEMPTS, - QUEUE_FLOW_CONTROL_SIZE_BYTES, - QUEUE_FLOW_RESUME_SIZE_BYTES, - QUEUE_FLOW_STOPPED, - ALERT_THRESHOLD_MESSAGE_AGE, - ALERT_THRESHOLD_MESSAGE_SIZE, - ALERT_THRESHOLD_QUEUE_DEPTH_BYTES, - ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, - ALERT_REPEAT_GAP, - PRIORITIES - )); - - - //children - Collection<Binding> getBindings(); - Collection<Consumer> getConsumers(); - - - //operations - - void visit(QueueEntryVisitor visitor); - - void delete(); - - void setNotificationListener(QueueNotificationListener listener); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueNotificationListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueNotificationListener.java deleted file mode 100644 index ab601f685c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueNotificationListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.qpid.server.model;
-
-import org.apache.qpid.server.queue.NotificationCheck;
-
-public interface QueueNotificationListener
-{
- void notifyClients(NotificationCheck notification, Queue queue, String notificationMsg);
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueType.java deleted file mode 100644 index 96f2a7e2e5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueType.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -public enum QueueType -{ - STANDARD, - PRIORITY, - LVQ, - SORTED -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Session.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Session.java deleted file mode 100644 index e813d0c129..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Session.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -public interface Session extends ConfiguredObject -{ - // Statistics - - public static final String BYTES_IN = "bytesIn"; - public static final String BYTES_OUT = "bytesOut"; - public static final String CONSUMER_COUNT = "consumerCount"; - public static final String LOCAL_TRANSACTION_BEGINS = "localTransactionBegins"; - public static final String LOCAL_TRANSACTION_OPEN = "localTransactionOpen"; - public static final String LOCAL_TRANSACTION_ROLLBACKS = "localTransactionRollbacks"; - public static final String STATE_CHANGED = "stateChanged"; - public static final String UNACKNOWLEDGED_BYTES = "unacknowledgedBytes"; - public static final String UNACKNOWLEDGED_MESSAGES = "unacknowledgedMessages"; - public static final String XA_TRANSACTION_BRANCH_ENDS = "xaTransactionBranchEnds"; - public static final String XA_TRANSACTION_BRANCH_STARTS = "xaTransactionBranchStarts"; - public static final String XA_TRANSACTION_BRANCH_SUSPENDS = "xaTransactionBranchSuspends"; - - public static final Collection<String> AVAILABLE_STATISTICS = - Collections.unmodifiableCollection(Arrays.asList(BYTES_IN, BYTES_OUT, CONSUMER_COUNT, - LOCAL_TRANSACTION_BEGINS, - LOCAL_TRANSACTION_OPEN, - LOCAL_TRANSACTION_ROLLBACKS, STATE_CHANGED, - UNACKNOWLEDGED_BYTES, UNACKNOWLEDGED_MESSAGES, - XA_TRANSACTION_BRANCH_ENDS, XA_TRANSACTION_BRANCH_STARTS, - XA_TRANSACTION_BRANCH_SUSPENDS)); - - - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String STATE = "state"; - public static final String DURABLE = "durable"; - public static final String LIFETIME_POLICY = "lifetimePolicy"; - public static final String TIME_TO_LIVE = "timeToLive"; - public static final String CREATED = "created"; - public static final String UPDATED = "updated"; - - public static final String CHANNEL_ID = "channelId"; - // PRODUCER_FLOW_BLOCKED is exposed as an interim step. We will expose attribute(s) that exposing - // available credit of both producer and consumer sides. - public static final String PRODUCER_FLOW_BLOCKED = "producerFlowBlocked"; - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableCollection(Arrays.asList(ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - CHANNEL_ID, - PRODUCER_FLOW_BLOCKED)); - - Collection<Consumer> getSubscriptions(); - Collection<Publisher> getPublishers(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/State.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/State.java deleted file mode 100644 index a4287e09b1..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/State.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -public enum State -{ - INITIALISING, - QUIESCED, - STOPPED, - ACTIVE, - DELETED, - REPLICA, - ERRORED -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Statistics.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Statistics.java deleted file mode 100644 index 92d6f47741..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Statistics.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.qpid.server.model; - -import java.util.Collection; - -public interface Statistics -{ - Collection<String> getStatisticNames(); - public Object getStatistic(String name); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java deleted file mode 100644 index ae6e5ac43a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.EnumSet; - -public enum Transport -{ - TCP, - SSL; - - public static Transport valueOfObject(Object transportObject) - { - Transport transport; - if (transportObject instanceof Transport) - { - transport = (Transport) transportObject; - } - else - { - try - { - transport = Transport.valueOf(String.valueOf(transportObject)); - } - catch (Exception e) - { - throw new IllegalArgumentException("Can't convert '" + transportObject - + "' to one of the supported transports: " + EnumSet.allOf(Transport.class), e); - } - } - return transport; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java deleted file mode 100644 index d313e1832f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.security.GeneralSecurityException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import javax.net.ssl.TrustManager; - -public interface TrustStore extends ConfiguredObject -{ - String ID = "id"; - String NAME = "name"; - String DURABLE = "durable"; - String LIFETIME_POLICY = "lifetimePolicy"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String CREATED = "created"; - String UPDATED = "updated"; - String DESCRIPTION = "description"; - - String PATH = "path"; - String PASSWORD = "password"; - String TYPE = "type"; - String PEERS_ONLY = "peersOnly"; - String TRUST_MANAGER_FACTORY_ALGORITHM = "trustManagerFactoryAlgorithm"; - - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - DESCRIPTION, - PATH, - PASSWORD, - TYPE, - PEERS_ONLY, - TRUST_MANAGER_FACTORY_ALGORITHM - )); - - public String getPassword(); - - public void setPassword(String password); - - public TrustManager[] getTrustManagers() throws GeneralSecurityException; - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java deleted file mode 100644 index 7def89025d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.UUID; - -public class UUIDGenerator -{ - //Generates a random UUID. Used primarily by tests. - public static UUID generateRandomUUID() - { - return UUID.randomUUID(); - } - - private static UUID createUUID(String objectType, String... names) - { - StringBuilder sb = new StringBuilder(); - sb.append(objectType); - - for(String name : names) - { - sb.append("/").append(name); - } - - return UUID.nameUUIDFromBytes(sb.toString().getBytes()); - } - - public static UUID generateExchangeUUID(String exchangeName, String virtualHostName) - { - return createUUID(Exchange.class.getName(), virtualHostName, exchangeName); - } - - public static UUID generateQueueUUID(String queueName, String virtualHostName) - { - return createUUID(Queue.class.getName(), virtualHostName, queueName); - } - - public static UUID generateBindingUUID(String exchangeName, String queueName, String bindingKey, String virtualHostName) - { - return createUUID(Binding.class.getName(), virtualHostName, exchangeName, queueName, bindingKey); - } - - public static UUID generateUserUUID(String authenticationProviderName, String userName) - { - return createUUID(User.class.getName(), authenticationProviderName, userName); - } - - public static UUID generateGroupUUID(String groupProviderName, String groupName) - { - return createUUID(Group.class.getName(), groupProviderName, groupName); - } - - public static UUID generateVhostUUID(String virtualHostName) - { - return createUUID(VirtualHost.class.getName(), virtualHostName); - } - - public static UUID generateVhostAliasUUID(String virtualHostName, String portName) - { - return createUUID(VirtualHostAlias.class.getName(), virtualHostName, portName); - } - - public static UUID generateConsumerUUID(String virtualHostName, String queueName, String connectionRemoteAddress, String channelNumber, String consumerName) - { - return createUUID(Consumer.class.getName(), virtualHostName, queueName, connectionRemoteAddress, channelNumber, consumerName); - } - - public static UUID generateGroupMemberUUID(String groupProviderName, String groupName, String groupMemberName) - { - return createUUID(GroupMember.class.getName(), groupProviderName, groupName, groupMemberName); - } - - public static UUID generateBrokerChildUUID(String type, String childName) - { - return createUUID(type, childName); - } - - public static UUID generatePreferencesProviderUUID(String preferencesProviderName, String authenticationProviderName) - { - return createUUID(PreferencesProvider.class.getName(), authenticationProviderName, preferencesProviderName); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/User.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/User.java deleted file mode 100644 index f9d6f17ffd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/User.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -public interface User extends ConfiguredObject -{ - String CREATED = "created"; - String DURABLE = "durable"; - String ID = "id"; - String LIFETIME_POLICY = "lifetimePolicy"; - String NAME = "name"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String UPDATED = "updated"; - String PASSWORD = "password"; - - // Attributes - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - PASSWORD - )); - - public void setPassword(String password); - - public Map<String, Object> getPreferences(); - - public Object getPreference(String name); - - public Map<String, Object> setPreferences(Map<String, Object> preferences); - - public Map<String, Object> replacePreferences(Map<String, Object> newPreferences); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java deleted file mode 100644 index ae07005679..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import org.apache.qpid.server.queue.QueueEntry; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.store.MessageStore; - -import java.security.AccessControlException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -public interface VirtualHost extends ConfiguredObject -{ - // Statistics - - public static final String BYTES_IN = "bytesIn"; - public static final String BYTES_OUT = "bytesOut"; - public static final String BYTES_RETAINED = "bytesRetained"; - public static final String LOCAL_TRANSACTION_BEGINS = "localTransactionBegins"; - public static final String LOCAL_TRANSACTION_ROLLBACKS = "localTransactionRollbacks"; - public static final String MESSAGES_IN = "messagesIn"; - public static final String MESSAGES_OUT = "messagesOut"; - public static final String MESSAGES_RETAINED = "messagesRetained"; - public static final String STATE_CHANGED = "stateChanged"; - public static final String XA_TRANSACTION_BRANCH_ENDS = "xaTransactionBranchEnds"; - public static final String XA_TRANSACTION_BRANCH_STARTS = "xaTransactionBranchStarts"; - public static final String XA_TRANSACTION_BRANCH_SUSPENDS = "xaTransactionBranchSuspends"; - public static final String QUEUE_COUNT = "queueCount"; - public static final String EXCHANGE_COUNT = "exchangeCount"; - public static final String CONNECTION_COUNT = "connectionCount"; - - public static final Collection<String> AVAILABLE_STATISTICS = - Collections.unmodifiableList( - Arrays.asList(BYTES_IN, BYTES_OUT, BYTES_RETAINED, LOCAL_TRANSACTION_BEGINS, - LOCAL_TRANSACTION_ROLLBACKS, MESSAGES_IN, MESSAGES_OUT, MESSAGES_RETAINED, STATE_CHANGED, - XA_TRANSACTION_BRANCH_ENDS, XA_TRANSACTION_BRANCH_STARTS, XA_TRANSACTION_BRANCH_SUSPENDS, - QUEUE_COUNT, EXCHANGE_COUNT, CONNECTION_COUNT)); - - String QUEUE_ALERT_REPEAT_GAP = "queue.alertRepeatGap"; - String QUEUE_ALERT_THRESHOLD_MESSAGE_AGE = "queue.alertThresholdMessageAge"; - String QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE = "queue.alertThresholdMessageSize"; - String QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES = "queue.alertThresholdQueueDepthBytes"; - String QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES = "queue.alertThresholdQueueDepthMessages"; - String QUEUE_DEAD_LETTER_QUEUE_ENABLED = "queue.deadLetterQueueEnabled"; - String QUEUE_MAXIMUM_DELIVERY_ATTEMPTS = "queue.maximumDeliveryAttempts"; - String QUEUE_FLOW_CONTROL_SIZE_BYTES = "queue.flowControlSizeBytes"; - String QUEUE_FLOW_RESUME_SIZE_BYTES = "queue.flowResumeSizeBytes"; - - String HOUSEKEEPING_CHECK_PERIOD = "housekeepingCheckPeriod"; - String STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE = "storeTransactionIdleTimeoutClose"; - String STORE_TRANSACTION_IDLE_TIMEOUT_WARN = "storeTransactionIdleTimeoutWarn"; - String STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE = "storeTransactionOpenTimeoutClose"; - String STORE_TRANSACTION_OPEN_TIMEOUT_WARN = "storeTransactionOpenTimeoutWarn"; - String STORE_TYPE = "storeType"; - String STORE_PATH = "storePath"; - String CONFIG_STORE_TYPE = "configStoreType"; - String CONFIG_STORE_PATH = "configStorePath"; - String SUPPORTED_EXCHANGE_TYPES = "supportedExchangeTypes"; - String SUPPORTED_QUEUE_TYPES = "supportedQueueTypes"; - String CREATED = "created"; - String DURABLE = "durable"; - String ID = "id"; - String LIFETIME_POLICY = "lifetimePolicy"; - String NAME = "name"; - String STATE = "state"; - String TIME_TO_LIVE = "timeToLive"; - String TYPE = "type"; - String UPDATED = "updated"; - String CONFIG_PATH = "configPath"; - - // Attributes - public static final Collection<String> AVAILABLE_ATTRIBUTES = - Collections.unmodifiableList( - Arrays.asList( - ID, - NAME, - TYPE, - STATE, - DURABLE, - LIFETIME_POLICY, - TIME_TO_LIVE, - CREATED, - UPDATED, - SUPPORTED_EXCHANGE_TYPES, - SUPPORTED_QUEUE_TYPES, - QUEUE_DEAD_LETTER_QUEUE_ENABLED, - HOUSEKEEPING_CHECK_PERIOD, - QUEUE_MAXIMUM_DELIVERY_ATTEMPTS, - QUEUE_FLOW_CONTROL_SIZE_BYTES, - QUEUE_FLOW_RESUME_SIZE_BYTES, - CONFIG_STORE_TYPE, - CONFIG_STORE_PATH, - STORE_TYPE, - STORE_PATH, - STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE, - STORE_TRANSACTION_IDLE_TIMEOUT_WARN, - STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE, - STORE_TRANSACTION_OPEN_TIMEOUT_WARN, - QUEUE_ALERT_REPEAT_GAP, - QUEUE_ALERT_THRESHOLD_MESSAGE_AGE, - QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE, - QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES, - QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, - CONFIG_PATH)); - - int CURRENT_CONFIG_VERSION = 3; - - //children - Collection<VirtualHostAlias> getAliases(); - Collection<Connection> getConnections(); - Collection<Queue> getQueues(); - Collection<Exchange> getExchanges(); - - Exchange createExchange(String name, State initialState, boolean durable, - LifetimePolicy lifetime, long ttl, String type, Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException; - - Queue createQueue(String name, State initialState, boolean durable, - boolean exclusive, LifetimePolicy lifetime, long ttl, Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException; - - Collection<String> getExchangeTypes(); - - public static interface Transaction - { - void dequeue(QueueEntry entry); - - void copy(QueueEntry entry, Queue queue); - - void move(QueueEntry entry, Queue queue); - - } - - public static interface TransactionalOperation - { - void withinTransaction(Transaction txn); - } - - void executeTransaction(TransactionalOperation op); - - /** - * A temporary hack to expose host security manager. - * TODO We need to add and implement an authorization provider configured object instead - */ - SecurityManager getSecurityManager(); - - MessageStore getMessageStore(); - - String getType(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHostAlias.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHostAlias.java deleted file mode 100644 index 31403d78e5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHostAlias.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model; - -import java.security.AccessControlException; -import java.util.Collection; - -public interface VirtualHostAlias extends ConfiguredObject -{ - // parents - Port getPort(); - VirtualHost getVirtualHost(); - - // children - Collection<AuthenticationMethod> getAuthenticationMethods(); - - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java deleted file mode 100644 index 9ac2cb00a3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java +++ /dev/null @@ -1,477 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.model.ConfigurationChangeListener; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.updater.ChangeAttributesTask; -import org.apache.qpid.server.configuration.updater.ChangeStateTask; -import org.apache.qpid.server.configuration.updater.CreateChildTask; -import org.apache.qpid.server.configuration.updater.SetAttributeTask; -import org.apache.qpid.server.configuration.updater.TaskExecutor; - -public abstract class AbstractAdapter implements ConfiguredObject -{ - private static final Object ID = "id"; - private final Map<String,Object> _attributes = new HashMap<String, Object>(); - private final Map<Class<? extends ConfiguredObject>, ConfiguredObject> _parents = - new HashMap<Class<? extends ConfiguredObject>, ConfiguredObject>(); - private final Collection<ConfigurationChangeListener> _changeListeners = - new ArrayList<ConfigurationChangeListener>(); - - private final UUID _id; - private final Map<String, Object> _defaultAttributes = new HashMap<String, Object>(); - private final TaskExecutor _taskExecutor; - - protected AbstractAdapter(UUID id, Map<String, Object> defaults, Map<String, Object> attributes, TaskExecutor taskExecutor) - { - this(id, defaults, attributes, taskExecutor, true); - } - - protected AbstractAdapter(UUID id, Map<String, Object> defaults, Map<String, Object> attributes, - TaskExecutor taskExecutor, boolean filterAttributes) - - { - _taskExecutor = taskExecutor; - _id = id; - if (attributes != null) - { - Collection<String> names = getAttributeNames(); - if(filterAttributes) - { - for (String name : names) - { - if (attributes.containsKey(name)) - { - final Object value = attributes.get(name); - if(value != null) - { - _attributes.put(name, value); - } - } - } - } - else - { - for(Map.Entry<String, Object> entry : attributes.entrySet()) - { - if(entry.getValue()!=null) - { - _attributes.put(entry.getKey(),entry.getValue()); - } - } - } - } - if (defaults != null) - { - _defaultAttributes.putAll(defaults); - } - } - - protected AbstractAdapter(UUID id, TaskExecutor taskExecutor) - { - this(id, null, null, taskExecutor); - } - - public final UUID getId() - { - return _id; - } - - public State getDesiredState() - { - return null; //TODO - } - - @Override - public final State setDesiredState(final State currentState, final State desiredState) - throws IllegalStateTransitionException, AccessControlException - { - if (_taskExecutor.isTaskExecutorThread()) - { - authoriseSetDesiredState(currentState, desiredState); - if (setState(currentState, desiredState)) - { - notifyStateChanged(currentState, desiredState); - return desiredState; - } - else - { - return getActualState(); - } - } - else - { - return (State)_taskExecutor.submitAndWait(new ChangeStateTask(this, currentState, desiredState)); - } - } - - /** - * @return true when the state has been successfully updated to desiredState or false otherwise - */ - protected abstract boolean setState(State currentState, State desiredState); - - protected void notifyStateChanged(final State currentState, final State desiredState) - { - synchronized (_changeListeners) - { - List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners); - for(ConfigurationChangeListener listener : copy) - { - listener.stateChanged(this, currentState, desiredState); - } - } - } - - public void addChangeListener(final ConfigurationChangeListener listener) - { - if(listener == null) - { - throw new NullPointerException("Cannot add a null listener"); - } - synchronized (_changeListeners) - { - if(!_changeListeners.contains(listener)) - { - _changeListeners.add(listener); - } - } - } - - public boolean removeChangeListener(final ConfigurationChangeListener listener) - { - if(listener == null) - { - throw new NullPointerException("Cannot remove a null listener"); - } - synchronized (_changeListeners) - { - return _changeListeners.remove(listener); - } - } - - protected void childAdded(ConfiguredObject child) - { - synchronized (_changeListeners) - { - List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners); - for(ConfigurationChangeListener listener : copy) - { - listener.childAdded(this, child); - } - } - } - - protected void childRemoved(ConfiguredObject child) - { - synchronized (_changeListeners) - { - List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners); - for(ConfigurationChangeListener listener : copy) - { - listener.childRemoved(this, child); - } - } - } - - protected void attributeSet(String attrinuteName, Object oldAttributeValue, Object newAttributeValue) - { - synchronized (_changeListeners) - { - List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners); - for(ConfigurationChangeListener listener : copy) - { - listener.attributeSet(this, attrinuteName, oldAttributeValue, newAttributeValue); - } - } - } - - private final Object getDefaultAttribute(String name) - { - return _defaultAttributes.get(name); - } - - @Override - public Object getAttribute(String name) - { - Object value = getActualAttribute(name); - if (value == null) - { - value = getDefaultAttribute(name); - } - return value; - } - - @Override - public final Map<String, Object> getActualAttributes() - { - synchronized (_attributes) - { - return new HashMap<String, Object>(_attributes); - } - } - - private Object getActualAttribute(final String name) - { - synchronized (_attributes) - { - return _attributes.get(name); - } - } - - public Object setAttribute(final String name, final Object expected, final Object desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - if (_taskExecutor.isTaskExecutorThread()) - { - authoriseSetAttribute(name, expected, desired); - if (changeAttribute(name, expected, desired)) - { - attributeSet(name, expected, desired); - return desired; - } - else - { - return getAttribute(name); - } - } - else - { - return _taskExecutor.submitAndWait(new SetAttributeTask(this, name, expected, desired)); - } - } - - protected boolean changeAttribute(final String name, final Object expected, final Object desired) - { - synchronized (_attributes) - { - Object currentValue = getAttribute(name); - if((currentValue == null && expected == null) - || (currentValue != null && currentValue.equals(expected))) - { - //TODO: dont put nulls - _attributes.put(name, desired); - return true; - } - else - { - return false; - } - } - } - - public <T extends ConfiguredObject> T getParent(final Class<T> clazz) - { - synchronized (_parents) - { - return (T) _parents.get(clazz); - } - } - - protected <T extends ConfiguredObject> void addParent(Class<T> clazz, T parent) - { - synchronized (_parents) - { - _parents.put(clazz, parent); - } - } - - protected <T extends ConfiguredObject> void removeParent(Class<T> clazz) - { - synchronized (this) - { - _parents.remove(clazz); - } - } - - public Collection<String> getAttributeNames() - { - synchronized(_attributes) - { - return new ArrayList<String>(_attributes.keySet()); - } - } - - @Override - public String toString() - { - return getClass().getSimpleName() + " [id=" + _id + ", name=" + getName() + "]"; - } - - @SuppressWarnings("unchecked") - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - if (_taskExecutor.isTaskExecutorThread()) - { - authoriseCreateChild(childClass, attributes, otherParents); - C child = addChild(childClass, attributes, otherParents); - if (child != null) - { - childAdded(child); - } - return child; - } - else - { - return (C)_taskExecutor.submitAndWait(new CreateChildTask(this, childClass, attributes, otherParents)); - } - } - - protected <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - throw new UnsupportedOperationException(); - } - - - protected TaskExecutor getTaskExecutor() - { - return _taskExecutor; - } - - @Override - public void setAttributes(final Map<String, Object> attributes) throws IllegalStateException, AccessControlException, IllegalArgumentException - { - if (getTaskExecutor().isTaskExecutorThread()) - { - authoriseSetAttributes(attributes); - changeAttributes(attributes); - } - else - { - getTaskExecutor().submitAndWait(new ChangeAttributesTask(this, attributes)); - } - } - - protected void changeAttributes(final Map<String, Object> attributes) - { - validateChangeAttributes(attributes); - Collection<String> names = getAttributeNames(); - for (String name : names) - { - if (attributes.containsKey(name)) - { - Object desired = attributes.get(name); - Object expected = getAttribute(name); - if (changeAttribute(name, expected, desired)) - { - attributeSet(name, expected, desired); - } - } - } - } - - protected void validateChangeAttributes(final Map<String, Object> attributes) - { - if (attributes.containsKey(ID)) - { - UUID id = getId(); - Object idAttributeValue = attributes.get(ID); - if (idAttributeValue != null && !idAttributeValue.equals(id.toString())) - { - throw new IllegalConfigurationException("Cannot change existing configured object id"); - } - } - } - - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - // allowed by default - } - - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - // allowed by default - } - - protected <C extends ConfiguredObject> void authoriseCreateChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) throws AccessControlException - { - // allowed by default - } - - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - // allowed by default - } - - protected Map<String, Object> getDefaultAttributes() - { - return _defaultAttributes; - } - - /** - * Returns a map of effective attribute values that would result - * if applying the supplied changes. Does not apply the changes. - */ - protected Map<String, Object> generateEffectiveAttributes(Map<String,Object> changedValues) - { - //Build a new set of effective attributes that would be - //the result of applying the attribute changes, so we - //can validate the configuration that would result - - Map<String, Object> defaultValues = getDefaultAttributes(); - Map<String, Object> existingActualValues = getActualAttributes(); - - //create a new merged map, starting with the defaults - Map<String, Object> merged = new HashMap<String, Object>(defaultValues); - - for(String name : getAttributeNames()) - { - if(changedValues.containsKey(name)) - { - Object changedValue = changedValues.get(name); - if(changedValue != null) - { - //use the new non-null value for the merged values - merged.put(name, changedValue); - } - else - { - //we just use the default (if there was one) since the changed - //value is null and effectively clears any existing actual value - } - } - else if(existingActualValues.get(name) != null) - { - //Use existing non-null actual value for the merge - merged.put(name, existingActualValues.get(name)); - } - else - { - //There was neither a change or an existing non-null actual - //value, so just use the default value (if there was one). - } - } - - return merged; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java deleted file mode 100644 index 707cf8076d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.util.MapValueConverter; - -public abstract class AbstractKeyStoreAdapter extends AbstractAdapter -{ - public static final String DUMMY_PASSWORD_MASK = "********"; - public static final String DEFAULT_KEYSTORE_TYPE = java.security.KeyStore.getDefaultType(); - - private String _name; - private String _password; - - protected AbstractKeyStoreAdapter(UUID id, Broker broker, Map<String, Object> defaults, - Map<String, Object> attributes) - { - super(id, defaults, attributes, broker.getTaskExecutor()); - addParent(Broker.class, broker); - - _name = MapValueConverter.getStringAttribute(TrustStore.NAME, attributes); - _password = MapValueConverter.getStringAttribute(TrustStore.PASSWORD, attributes); - MapValueConverter.assertMandatoryAttribute(KeyStore.PATH, attributes); - } - - @Override - public String getName() - { - return _name; - } - - @Override - public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException - { - throw new IllegalStateException(); - } - - @Override - public State getActualState() - { - return State.ACTIVE; - } - - @Override - public boolean isDurable() - { - return true; - } - - @Override - public void setDurable(boolean durable) throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - return Collections.emptySet(); - } - - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - throw new UnsupportedOperationException(); - } - - @Override - public Object getAttribute(String name) - { - if(KeyStore.ID.equals(name)) - { - return getId(); - } - else if(KeyStore.NAME.equals(name)) - { - return getName(); - } - else if(KeyStore.STATE.equals(name)) - { - return getActualState(); - } - else if(KeyStore.DURABLE.equals(name)) - { - return isDurable(); - } - else if(KeyStore.LIFETIME_POLICY.equals(name)) - { - return getLifetimePolicy(); - } - else if(KeyStore.TIME_TO_LIVE.equals(name)) - { - return getTimeToLive(); - } - else if(KeyStore.CREATED.equals(name)) - { - - } - else if(KeyStore.UPDATED.equals(name)) - { - - } - else if(KeyStore.PASSWORD.equals(name)) - { - // For security reasons we don't expose the password - if (getPassword() != null) - { - return DUMMY_PASSWORD_MASK; - } - - return null; - } - - return super.getAttribute(name); - } - - public String getPassword() - { - return _password; - } - - public void setPassword(String password) - { - _password = password; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java deleted file mode 100644 index 2867a92410..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Plugin; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.security.access.Operation; - -public abstract class AbstractPluginAdapter extends AbstractAdapter implements Plugin -{ - private Broker _broker; - - protected AbstractPluginAdapter(UUID id, Map<String, Object> defaults, Map<String, Object> attributes, Broker broker) - { - super(id, defaults, attributes, broker.getTaskExecutor()); - _broker = broker; - addParent(Broker.class, broker); - } - - @Override - public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException - { - throw new UnsupportedOperationException(); - } - - @Override - public State getActualState() - { - return null; - } - - @Override - public boolean isDurable() - { - return true; - } - - @Override - public void setDurable(boolean durable) throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException(); - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException(); - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new UnsupportedOperationException(); - } - - @Override - public Statistics getStatistics() - { - return null; - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - return Collections.emptyList(); - } - - @Override - public Collection<String> getAttributeNames() - { - return AVAILABLE_ATTRIBUTES; - } - - @Override - public Object getAttribute(String name) - { - if (ID.equals(name)) - { - return getId(); - } - else if (STATE.equals(name)) - { - return getActualState(); - } - else if (DURABLE.equals(name)) - { - return isDurable(); - } - else if (LIFETIME_POLICY.equals(name)) - { - return getLifetimePolicy(); - } - else if (TIME_TO_LIVE.equals(name)) - { - return getTimeToLive(); - } - else if (CREATED.equals(name)) - { - - } - else if (UPDATED.equals(name)) - { - - } - return super.getAttribute(name); - } - - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, - ConfiguredObject... otherParents) - { - throw new UnsupportedOperationException(); - } - - @Override - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - if(desiredState == State.DELETED) - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), Plugin.class, Operation.DELETE)) - { - throw new AccessControlException("Deletion of plugin is denied"); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), Plugin.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of plugin attribute is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), Plugin.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of plugin attributes is denied"); - } - } - - protected Broker getBroker() - { - return _broker; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AccessControlProviderAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AccessControlProviderAdapter.java deleted file mode 100644 index a6fe191523..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AccessControlProviderAdapter.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.model.AccessControlProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.plugin.AccessControlFactory; -import org.apache.qpid.server.security.AccessControl; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.util.MapValueConverter; - -public class AccessControlProviderAdapter extends AbstractAdapter implements AccessControlProvider -{ - private static final Logger LOGGER = Logger.getLogger(AccessControlProviderAdapter.class); - - protected AccessControl _accessControl; - protected final Broker _broker; - - protected Collection<String> _supportedAttributes; - protected Map<String, AccessControlFactory> _factories; - private AtomicReference<State> _state; - - public AccessControlProviderAdapter(UUID id, Broker broker, AccessControl accessControl, Map<String, Object> attributes, Collection<String> attributeNames) - { - super(id, null, null, broker.getTaskExecutor()); - - if (accessControl == null) - { - throw new IllegalArgumentException("AccessControl must not be null"); - } - - _accessControl = accessControl; - _broker = broker; - _supportedAttributes = createSupportedAttributes(attributeNames); - addParent(Broker.class, broker); - - State state = MapValueConverter.getEnumAttribute(State.class, STATE, attributes, State.INITIALISING); - _state = new AtomicReference<State>(state); - - // set attributes now after all attribute names are known - if (attributes != null) - { - for (String name : _supportedAttributes) - { - if (attributes.containsKey(name)) - { - changeAttribute(name, null, attributes.get(name)); - } - } - } - } - - protected Collection<String> createSupportedAttributes(Collection<String> factoryAttributes) - { - List<String> attributesNames = new ArrayList<String>(AVAILABLE_ATTRIBUTES); - if (factoryAttributes != null) - { - attributesNames.addAll(factoryAttributes); - } - - return Collections.unmodifiableCollection(attributesNames); - } - - @Override - public String getName() - { - return (String)getAttribute(AccessControlProvider.NAME); - } - - @Override - public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException - { - return null; - } - - @Override - public State getActualState() - { - return _state.get(); - } - - @Override - public boolean isDurable() - { - return true; - } - - @Override - public void setDurable(boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return null; - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return 0; - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public Collection<String> getAttributeNames() - { - return _supportedAttributes; - } - - @Override - public Object getAttribute(String name) - { - if(CREATED.equals(name)) - { - // TODO - } - else if(DURABLE.equals(name)) - { - return true; - } - else if(ID.equals(name)) - { - return getId(); - } - else if(LIFETIME_POLICY.equals(name)) - { - return LifetimePolicy.PERMANENT; - } - else if(STATE.equals(name)) - { - return getActualState(); - } - else if(TIME_TO_LIVE.equals(name)) - { - // TODO - } - else if(UPDATED.equals(name)) - { - // TODO - } - return super.getAttribute(name); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - return Collections.emptySet(); - } - - @Override - public boolean setState(State currentState, State desiredState) - throws IllegalStateTransitionException, AccessControlException - { - State state = _state.get(); - - if(desiredState == State.DELETED) - { - return _state.compareAndSet(state, State.DELETED); - } - else if (desiredState == State.QUIESCED) - { - return _state.compareAndSet(state, State.QUIESCED); - } - else if(desiredState == State.ACTIVE) - { - if ((state == State.INITIALISING || state == State.QUIESCED) && _state.compareAndSet(state, State.ACTIVE)) - { - try - { - _accessControl.open(); - return true; - } - catch(RuntimeException e) - { - _state.compareAndSet(State.ACTIVE, State.ERRORED); - if (_broker.isManagementMode()) - { - LOGGER.warn("Failed to activate ACL provider: " + getName(), e); - } - else - { - throw e; - } - } - } - else - { - throw new IllegalStateException("Can't activate access control provider in " + state + " state"); - } - } - else if(desiredState == State.STOPPED) - { - if(_state.compareAndSet(state, State.STOPPED)) - { - _accessControl.close(); - return true; - } - - return false; - } - return false; - } - - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - throw new UnsupportedOperationException("Changing attributes on AccessControlProvider is not supported"); - } - - @Override - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - if(desiredState == State.DELETED) - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AccessControlProvider.class, Operation.DELETE)) - { - throw new AccessControlException("Deletion of AccessControlProvider is denied"); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AccessControlProvider.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of AccessControlProvider attributes is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AccessControlProvider.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of AccessControlProvider attributes is denied"); - } - } - - public AccessControl getAccessControl() - { - return _accessControl; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AccessControlProviderFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AccessControlProviderFactory.java deleted file mode 100644 index 6cdf2f2c1a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AccessControlProviderFactory.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.model.AccessControlProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.plugin.AccessControlFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; -import org.apache.qpid.server.security.AccessControl; - -public class AccessControlProviderFactory -{ - private final Iterable<AccessControlFactory> _factories; - private Collection<String> _supportedAcessControlProviders; - - public AccessControlProviderFactory(QpidServiceLoader<AccessControlFactory> accessControlFactoryServiceLoader) - { - _factories = accessControlFactoryServiceLoader.instancesOf(AccessControlFactory.class); - List<String> supportedAccessControlProviders = new ArrayList<String>(); - for (AccessControlFactory factory : _factories) - { - supportedAccessControlProviders.add(factory.getType()); - } - _supportedAcessControlProviders = Collections.unmodifiableCollection(supportedAccessControlProviders); - } - - /** - * Creates {@link AccessControlProvider} for given ID, {@link Broker} and attributes. - * <p> - * The configured {@link AccessControlFactory}'s are used to try to create the {@link AccessControlProvider}. - * The first non-null instance is returned. The factories are used in non-deterministic order. - */ - public AccessControlProvider create(UUID id, Broker broker, Map<String, Object> attributes) - { - AccessControlProvider ac = createAccessControlProvider(id, broker, attributes); - ac.getAccessControl().onCreate(); - - return ac; - } - - public AccessControlProvider recover(UUID id, Broker broker, Map<String, Object> attributes) - { - return createAccessControlProvider(id, broker, attributes); - } - - private AccessControlProvider createAccessControlProvider(UUID id, - Broker broker, Map<String, Object> attributes) - { - for (AccessControlFactory factory : _factories) - { - AccessControl accessControl = factory.createInstance(attributes); - if (accessControl != null) - { - return new AccessControlProviderAdapter(id, broker,accessControl, attributes, factory.getAttributeNames()); - } - } - - throw new IllegalArgumentException("No access control provider factory found for configuration attributes " + attributes); - } - - public Collection<String> getSupportedAuthenticationProviders() - { - return _supportedAcessControlProviders; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java deleted file mode 100644 index a4ce95e5aa..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; - -import java.net.InetSocketAddress; -import java.security.GeneralSecurityException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import javax.net.ssl.KeyManager; -import javax.net.ssl.SSLContext; - -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.BrokerMessages; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Protocol; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.protocol.AmqpProtocolVersion; -import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory; -import org.apache.qpid.transport.NetworkTransportConfiguration; -import org.apache.qpid.transport.network.IncomingNetworkTransport; -import org.apache.qpid.transport.network.security.ssl.QpidMultipleTrustManager; - -public class AmqpPortAdapter extends PortAdapter -{ - private final Broker _broker; - private IncomingNetworkTransport _transport; - - public AmqpPortAdapter(UUID id, Broker broker, Map<String, Object> attributes, Map<String, Object> defaultAttributes, TaskExecutor taskExecutor) - { - super(id, broker, attributes, defaultAttributes, taskExecutor); - _broker = broker; - } - - @Override - protected void onActivate() - { - Collection<Transport> transports = getTransports(); - Set<AmqpProtocolVersion> supported = convertFromModelProtocolsToAmqp(getProtocols()); - - SSLContext sslContext = null; - if (transports.contains(Transport.SSL)) - { - sslContext = createSslContext(); - } - - AmqpProtocolVersion defaultSupportedProtocolReply = getDefaultAmqpSupportedReply(); - - String bindingAddress = (String) getAttribute(Port.BINDING_ADDRESS); - if (WILDCARD_ADDRESS.equals(bindingAddress)) - { - bindingAddress = null; - } - Integer port = (Integer) getAttribute(Port.PORT); - InetSocketAddress bindingSocketAddress = null; - if ( bindingAddress == null ) - { - bindingSocketAddress = new InetSocketAddress(port); - } - else - { - bindingSocketAddress = new InetSocketAddress(bindingAddress, port); - } - - final NetworkTransportConfiguration settings = new ServerNetworkTransportConfiguration( - bindingSocketAddress, (Boolean)getAttribute(TCP_NO_DELAY), - (Integer)getAttribute(SEND_BUFFER_SIZE), (Integer)getAttribute(RECEIVE_BUFFER_SIZE), - (Boolean)getAttribute(NEED_CLIENT_AUTH), (Boolean)getAttribute(WANT_CLIENT_AUTH)); - - _transport = org.apache.qpid.transport.network.Transport.getIncomingTransportInstance(); - final MultiVersionProtocolEngineFactory protocolEngineFactory = new MultiVersionProtocolEngineFactory( - _broker, transports.contains(Transport.TCP) ? sslContext : null, - settings.wantClientAuth(), settings.needClientAuth(), - supported, defaultSupportedProtocolReply, this, transports.contains(Transport.TCP) ? Transport.TCP : Transport.SSL); - - _transport.accept(settings, protocolEngineFactory, transports.contains(Transport.TCP) ? null : sslContext); - for(Transport transport : getTransports()) - { - CurrentActor.get().message(BrokerMessages.LISTENING(String.valueOf(transport), getPort())); - } - } - - @Override - protected void onStop() - { - if (_transport != null) - { - for(Transport transport : getTransports()) - { - CurrentActor.get().message(BrokerMessages.SHUTTING_DOWN(String.valueOf(transport), getPort())); - } - _transport.close(); - } - } - - private Set<AmqpProtocolVersion> convertFromModelProtocolsToAmqp(Collection<Protocol> modelProtocols) - { - Set<AmqpProtocolVersion> amqpProtocols = new HashSet<AmqpProtocolVersion>(); - for (Protocol protocol : modelProtocols) - { - amqpProtocols.add(protocol.toAmqpProtocolVersion()); - } - return amqpProtocols; - } - - private SSLContext createSslContext() - { - KeyStore keyStore = getKeyStore(); - Collection<TrustStore> trustStores = getTrustStores(); - - boolean needClientCert = (Boolean)getAttribute(NEED_CLIENT_AUTH) || (Boolean)getAttribute(WANT_CLIENT_AUTH); - if (needClientCert && trustStores.isEmpty()) - { - throw new IllegalConfigurationException("Client certificate authentication is enabled on AMQP port '" - + this.getName() + "' but no trust store defined"); - } - - try - { - SSLContext sslContext = SSLContext.getInstance("TLS"); - KeyManager[] keyManagers = keyStore.getKeyManagers(); - - TrustManager[] trustManagers; - if(trustStores == null || trustStores.isEmpty()) - { - trustManagers = null; - } - else if(trustStores.size() == 1) - { - trustManagers = trustStores.iterator().next().getTrustManagers(); - } - else - { - Collection<TrustManager> trustManagerList = new ArrayList<TrustManager>(); - final QpidMultipleTrustManager mulTrustManager = new QpidMultipleTrustManager(); - - for(TrustStore ts : trustStores) - { - TrustManager[] managers = ts.getTrustManagers(); - if(managers != null) - { - for(TrustManager manager : managers) - { - if(manager instanceof X509TrustManager) - { - mulTrustManager.addTrustManager((X509TrustManager)manager); - } - else - { - trustManagerList.add(manager); - } - } - } - } - if(!mulTrustManager.isEmpty()) - { - trustManagerList.add(mulTrustManager); - } - trustManagers = trustManagerList.toArray(new TrustManager[trustManagerList.size()]); - } - sslContext.init(keyManagers, trustManagers, null); - - return sslContext; - - } - catch (GeneralSecurityException e) - { - throw new RuntimeException("Unable to create SSLContext for key or trust store", e); - } - } - - private AmqpProtocolVersion getDefaultAmqpSupportedReply() - { - String defaultAmqpSupportedReply = System.getProperty(BrokerProperties.PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY); - if (defaultAmqpSupportedReply != null) - { - return AmqpProtocolVersion.valueOf(defaultAmqpSupportedReply); - } - return null; - } - - class ServerNetworkTransportConfiguration implements NetworkTransportConfiguration - { - private final InetSocketAddress _bindingSocketAddress; - private final Boolean _tcpNoDelay; - private final Integer _sendBufferSize; - private final Integer _receiveBufferSize; - private final boolean _needClientAuth; - private final boolean _wantClientAuth; - - public ServerNetworkTransportConfiguration( - InetSocketAddress bindingSocketAddress, boolean tcpNoDelay, - int sendBufferSize, int receiveBufferSize, - boolean needClientAuth, boolean wantClientAuth) - { - _bindingSocketAddress = bindingSocketAddress; - _tcpNoDelay = tcpNoDelay; - _sendBufferSize = sendBufferSize; - _receiveBufferSize = receiveBufferSize; - _needClientAuth = needClientAuth; - _wantClientAuth = wantClientAuth; - } - - @Override - public boolean wantClientAuth() - { - return _wantClientAuth; - } - - @Override - public boolean needClientAuth() - { - return _needClientAuth; - } - - @Override - public Boolean getTcpNoDelay() - { - return _tcpNoDelay; - } - - @Override - public Integer getSendBufferSize() - { - return _sendBufferSize; - } - - @Override - public Integer getReceiveBufferSize() - { - return _receiveBufferSize; - } - - @Override - public InetSocketAddress getAddress() - { - return _bindingSocketAddress; - } - }; - - public String toString() - { - return getName(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java deleted file mode 100644 index cbf8e1ba30..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java +++ /dev/null @@ -1,826 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.io.IOException; -import java.security.AccessControlException; -import java.security.Principal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; - -import javax.security.auth.login.AccountNotFoundException; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.IntegrityViolationException; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.model.User; -import org.apache.qpid.server.model.VirtualHostAlias; -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.security.SubjectCreator; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; -import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; -import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.util.MapValueConverter; - -public abstract class AuthenticationProviderAdapter<T extends AuthenticationManager> extends AbstractAdapter implements AuthenticationProvider -{ - private static final Logger LOGGER = Logger.getLogger(AuthenticationProviderAdapter.class); - - protected T _authManager; - protected final Broker _broker; - - protected Collection<String> _supportedAttributes; - protected Map<String, AuthenticationManagerFactory> _factories; - private final AtomicReference<State> _state; - private PreferencesProviderCreator _preferencesProviderCreator; - private PreferencesProvider _preferencesProvider; - - private AuthenticationProviderAdapter(UUID id, Broker broker, final T authManager, Map<String, Object> attributes, Collection<String> attributeNames, PreferencesProviderCreator preferencesProviderCreator) - { - super(id, null, null, broker.getTaskExecutor()); - _authManager = authManager; - _broker = broker; - _supportedAttributes = createSupportedAttributes(attributeNames); - _factories = getAuthenticationManagerFactories(); - - State state = MapValueConverter.getEnumAttribute(State.class, STATE, attributes, State.INITIALISING); - _state = new AtomicReference<State>(state); - addParent(Broker.class, broker); - - _preferencesProviderCreator = preferencesProviderCreator; - - // set attributes now after all attribute names are known - if (attributes != null) - { - for (String name : _supportedAttributes) - { - if (attributes.containsKey(name)) - { - changeAttribute(name, null, attributes.get(name)); - } - } - } - } - - T getAuthManager() - { - return _authManager; - } - - @Override - public Collection<VirtualHostAlias> getVirtualHostPortBindings() - { - return Collections.emptyList(); - } - - @Override - public String getName() - { - return (String)getAttribute(AuthenticationProvider.NAME); - } - - @Override - public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException - { - return null; - } - - @Override - public State getActualState() - { - return _state.get(); - } - - @Override - public boolean isDurable() - { - return true; - } - - @Override - public void setDurable(boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return null; - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return 0; - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public Collection<String> getAttributeNames() - { - return _supportedAttributes; - } - - @Override - public Object getAttribute(String name) - { - if(CREATED.equals(name)) - { - // TODO - } - else if(DURABLE.equals(name)) - { - return true; - } - else if(ID.equals(name)) - { - return getId(); - } - else if(LIFETIME_POLICY.equals(name)) - { - return LifetimePolicy.PERMANENT; - } - else if(STATE.equals(name)) - { - return getActualState(); - } - else if(TIME_TO_LIVE.equals(name)) - { - // TODO - } - else if(UPDATED.equals(name)) - { - // TODO - } - return super.getAttribute(name); - } - - @SuppressWarnings("unchecked") - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if (clazz == PreferencesProvider.class && _preferencesProvider != null) - { - return (Collection<C>)Collections.<PreferencesProvider>singleton(_preferencesProvider); - } - return Collections.emptySet(); - } - - @Override - public boolean setState(State currentState, State desiredState) - throws IllegalStateTransitionException, AccessControlException - { - State state = _state.get(); - if(desiredState == State.DELETED) - { - String providerName = getName(); - - // verify that provider is not in use - Collection<Port> ports = new ArrayList<Port>(_broker.getPorts()); - for (Port port : ports) - { - if (providerName.equals(port.getAttribute(Port.AUTHENTICATION_PROVIDER))) - { - throw new IntegrityViolationException("Authentication provider '" + providerName + "' is set on port " + port.getName()); - } - } - - if ((state == State.INITIALISING || state == State.ACTIVE || state == State.STOPPED || state == State.QUIESCED || state == State.ERRORED) - && _state.compareAndSet(state, State.DELETED)) - { - _authManager.close(); - _authManager.onDelete(); - if (_preferencesProvider != null) - { - _preferencesProvider.setDesiredState(_preferencesProvider.getActualState(), State.DELETED); - } - return true; - } - else - { - throw new IllegalStateException("Cannot delete authentication provider in state: " + state); - } - } - else if(desiredState == State.ACTIVE) - { - if ((state == State.INITIALISING || state == State.QUIESCED || state == State.STOPPED) && _state.compareAndSet(state, State.ACTIVE)) - { - try - { - _authManager.initialise(); - if (_preferencesProvider != null) - { - _preferencesProvider.setDesiredState(_preferencesProvider.getActualState(), State.ACTIVE); - } - return true; - } - catch(RuntimeException e) - { - _state.compareAndSet(State.ACTIVE, State.ERRORED); - if (_broker.isManagementMode()) - { - LOGGER.warn("Failed to activate authentication provider: " + getName(), e); - } - else - { - throw e; - } - } - } - else - { - throw new IllegalStateException("Cannot activate authentication provider in state: " + state); - } - } - else if (desiredState == State.QUIESCED) - { - if (state == State.INITIALISING && _state.compareAndSet(state, State.QUIESCED)) - { - return true; - } - } - else if(desiredState == State.STOPPED) - { - if (_state.compareAndSet(state, State.STOPPED)) - { - _authManager.close(); - if (_preferencesProvider != null) - { - _preferencesProvider.setDesiredState(_preferencesProvider.getActualState(), State.STOPPED); - } - return true; - } - else - { - throw new IllegalStateException("Cannot stop authentication provider in state: " + state); - } - } - - return false; - } - - @Override - public SubjectCreator getSubjectCreator() - { - return new SubjectCreator(_authManager, _broker.getGroupProviders()); - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - Map<String, Object> effectiveAttributes = super.generateEffectiveAttributes(attributes); - AuthenticationManager manager = validateAttributes(effectiveAttributes); - manager.initialise(); - super.changeAttributes(attributes); - _authManager = (T)manager; - - // if provider was previously in ERRORED state then set its state to ACTIVE - _state.compareAndSet(State.ERRORED, State.ACTIVE); - } - - private Map<String, AuthenticationManagerFactory> getAuthenticationManagerFactories() - { - QpidServiceLoader<AuthenticationManagerFactory> loader = new QpidServiceLoader<AuthenticationManagerFactory>(); - Iterable<AuthenticationManagerFactory> factories = loader.atLeastOneInstanceOf(AuthenticationManagerFactory.class); - Map<String, AuthenticationManagerFactory> factoryMap = new HashMap<String, AuthenticationManagerFactory>(); - for (AuthenticationManagerFactory factory : factories) - { - factoryMap.put(factory.getType(), factory); - } - return factoryMap; - } - - protected Collection<String> createSupportedAttributes(Collection<String> factoryAttributes) - { - List<String> attributesNames = new ArrayList<String>(AVAILABLE_ATTRIBUTES); - if (factoryAttributes != null) - { - attributesNames.addAll(factoryAttributes); - } - return Collections.unmodifiableCollection(attributesNames); - } - - protected AuthenticationManager validateAttributes(Map<String, Object> attributes) - { - super.validateChangeAttributes(attributes); - - String newName = (String)attributes.get(NAME); - String currentName = getName(); - if (!currentName.equals(newName)) - { - throw new IllegalConfigurationException("Changing the name of authentication provider is not supported"); - } - String newType = (String)attributes.get(AuthenticationManagerFactory.ATTRIBUTE_TYPE); - String currentType = (String)getAttribute(AuthenticationManagerFactory.ATTRIBUTE_TYPE); - if (!currentType.equals(newType)) - { - throw new IllegalConfigurationException("Changing the type of authentication provider is not supported"); - } - AuthenticationManagerFactory managerFactory = _factories.get(newType); - if (managerFactory == null) - { - throw new IllegalConfigurationException("Cannot find authentication provider factory for type " + newType); - } - AuthenticationManager manager = managerFactory.createInstance(attributes); - if (manager == null) - { - throw new IllegalConfigurationException("Cannot change authentication provider " + newName + " of type " + newType + " with the given attributes"); - } - return manager; - } - - @Override - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - if(desiredState == State.DELETED) - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AuthenticationProvider.class, Operation.DELETE)) - { - throw new AccessControlException("Deletion of authentication provider is denied"); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AuthenticationProvider.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of authentication provider attributes is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AuthenticationProvider.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of authentication provider attributes is denied"); - } - } - - public PreferencesProvider getPreferencesProvider() - { - return _preferencesProvider; - } - - public void setPreferencesProvider(PreferencesProvider provider) - { - if (AnonymousAuthenticationManagerFactory.PROVIDER_TYPE.equals(getAttribute(TYPE))) - { - throw new IllegalConfigurationException("Cannot set preferences provider for anonymous authentication provider"); - } - _preferencesProvider = provider; - } - - @SuppressWarnings("unchecked") - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - if(childClass == PreferencesProvider.class) - { - String name = MapValueConverter.getStringAttribute(PreferencesProvider.NAME, attributes); - PreferencesProvider pp = _preferencesProviderCreator.create(UUIDGenerator.generatePreferencesProviderUUID(name, getName()), attributes, this); - pp.setDesiredState(State.INITIALISING, State.ACTIVE); - _preferencesProvider = pp; - return (C)pp; - } - throw new IllegalArgumentException("Cannot create child of class " + childClass.getSimpleName()); - } - - public static class SimpleAuthenticationProviderAdapter extends AuthenticationProviderAdapter<AuthenticationManager> - { - - public SimpleAuthenticationProviderAdapter( - UUID id, Broker broker, AuthenticationManager authManager, Map<String, Object> attributes, Collection<String> attributeNames, PreferencesProviderCreator preferencesProviderCreator) - { - super(id, broker,authManager, attributes, attributeNames, preferencesProviderCreator); - } - } - - public static class PrincipalDatabaseAuthenticationManagerAdapter - extends AuthenticationProviderAdapter<PrincipalDatabaseAuthenticationManager> - implements PasswordCredentialManagingAuthenticationProvider - { - public PrincipalDatabaseAuthenticationManagerAdapter( - UUID id, Broker broker, PrincipalDatabaseAuthenticationManager authManager, Map<String, Object> attributes, Collection<String> attributeNames, PreferencesProviderCreator preferencesProviderCreator) - { - super(id, broker, authManager, attributes, attributeNames, preferencesProviderCreator); - } - - @Override - public boolean createUser(String username, String password, Map<String, String> attributes) - { - if(getSecurityManager().authoriseUserOperation(Operation.CREATE, username)) - { - return getPrincipalDatabase().createPrincipal(new UsernamePrincipal(username), password.toCharArray()); - } - else - { - throw new AccessControlException("Do not have permission to create new user"); - } - } - - @Override - public void deleteUser(String username) throws AccountNotFoundException - { - if(getSecurityManager().authoriseUserOperation(Operation.DELETE, username)) - { - getPrincipalDatabase().deletePrincipal(new UsernamePrincipal(username)); - } - else - { - throw new AccessControlException("Cannot delete user " + username); - } - } - - private SecurityManager getSecurityManager() - { - return _broker.getSecurityManager(); - } - - private PrincipalDatabase getPrincipalDatabase() - { - return getAuthManager().getPrincipalDatabase(); - } - - @Override - public void setPassword(String username, String password) throws AccountNotFoundException - { - if(getSecurityManager().authoriseUserOperation(Operation.UPDATE, username)) - { - getPrincipalDatabase().updatePassword(new UsernamePrincipal(username), password.toCharArray()); - } - else - { - throw new AccessControlException("Do not have permission to set password"); - } - } - - @Override - public Map<String, Map<String, String>> getUsers() - { - - Map<String, Map<String,String>> users = new HashMap<String, Map<String, String>>(); - for(Principal principal : getPrincipalDatabase().getUsers()) - { - users.put(principal.getName(), Collections.<String, String>emptyMap()); - } - return users; - } - - public void reload() throws IOException - { - getPrincipalDatabase().reload(); - } - - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, - Map<String, Object> attributes, - ConfiguredObject... otherParents) - { - if(childClass == User.class) - { - String username = (String) attributes.get("name"); - String password = (String) attributes.get("password"); - Principal p = new UsernamePrincipal(username); - - if(createUser(username, password,null)) - { - @SuppressWarnings("unchecked") - C pricipalAdapter = (C) new PrincipalAdapter(p); - return pricipalAdapter; - } - else - { - //TODO? Silly interface on the PrincipalDatabase at fault - throw new RuntimeException("Failed to create user"); - } - } - - return super.addChild(childClass, attributes, otherParents); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if(clazz == User.class) - { - List<Principal> users = getPrincipalDatabase().getUsers(); - Collection<User> principals = new ArrayList<User>(users.size()); - for(Principal user : users) - { - principals.add(new PrincipalAdapter(user)); - } - @SuppressWarnings("unchecked") - Collection<C> unmodifiablePrincipals = (Collection<C>) Collections.unmodifiableCollection(principals); - return unmodifiablePrincipals; - } - else - { - return super.getChildren(clazz); - } - } - - @Override - protected void childAdded(ConfiguredObject child) - { - if (child instanceof User) - { - // no-op, prevent storing users in the broker store - return; - } - super.childAdded(child); - } - - @Override - protected void childRemoved(ConfiguredObject child) - { - if (child instanceof User) - { - // no-op, as per above, users are not in the store - return; - } - super.childRemoved(child); - } - - private class PrincipalAdapter extends AbstractAdapter implements User - { - private final Principal _user; - - public PrincipalAdapter(Principal user) - { - super(UUIDGenerator.generateUserUUID(PrincipalDatabaseAuthenticationManagerAdapter.this.getName(), user.getName()), - PrincipalDatabaseAuthenticationManagerAdapter.this.getTaskExecutor()); - _user = user; - - } - - @Override - public void setPassword(String password) - { - try - { - PrincipalDatabaseAuthenticationManagerAdapter.this.setPassword(_user.getName(), password); - } - catch (AccountNotFoundException e) - { - throw new IllegalStateException(e); - } - } - - @Override - public String getName() - { - return _user.getName(); - } - - @Override - public String setName(String currentName, String desiredName) - throws IllegalStateException, AccessControlException - { - throw new IllegalStateException("Names cannot be updated"); - } - - @Override - public State getActualState() - { - return State.ACTIVE; - } - - @Override - public boolean isDurable() - { - return true; - } - - @Override - public void setDurable(boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException("Durability cannot be updated"); - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException("LifetimePolicy cannot be updated"); - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException("ttl cannot be updated"); - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - return null; - } - - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, - Map<String, Object> attributes, - ConfiguredObject... otherParents) - { - return null; - } - - @Override - public Collection<String> getAttributeNames() - { - return User.AVAILABLE_ATTRIBUTES; - } - - @Override - public Object getAttribute(String name) - { - if(ID.equals(name)) - { - return getId(); - } - else if(PASSWORD.equals(name)) - { - return null; // for security reasons we don't expose the password - } - else if(NAME.equals(name)) - { - return getName(); - } - return super.getAttribute(name); - } - - @Override - public boolean changeAttribute(String name, Object expected, Object desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - if(name.equals(PASSWORD)) - { - setPassword((String)desired); - return true; - } - return super.changeAttribute(name, expected, desired); - } - - @Override - protected boolean setState(State currentState, State desiredState) - throws IllegalStateTransitionException, AccessControlException - { - if(desiredState == State.DELETED) - { - try - { - String userName = _user.getName(); - deleteUser(userName); - PreferencesProvider preferencesProvider = getPreferencesProvider(); - if (preferencesProvider != null) - { - preferencesProvider.deletePreferences(userName); - } - } - catch (AccountNotFoundException e) - { - LOGGER.warn("Failed to delete user " + _user, e); - } - return true; - } - return false; - } - - @Override - public Map<String, Object> getPreferences() - { - PreferencesProvider preferencesProvider = getPreferencesProvider(); - if (preferencesProvider == null) - { - return null; - } - return preferencesProvider.getPreferences(this.getName()); - } - - @Override - public Object getPreference(String name) - { - Map<String, Object> preferences = getPreferences(); - if (preferences == null) - { - return null; - } - return preferences.get(name); - } - - @Override - public Map<String, Object> setPreferences(Map<String, Object> preferences) - { - PreferencesProvider preferencesProvider = getPreferencesProvider(); - if (preferencesProvider == null) - { - return null; - } - return preferencesProvider.setPreferences(this.getName(), preferences); - } - - @Override - public Map<String, Object> replacePreferences(Map<String, Object> newPreferences) - { - PreferencesProvider preferencesProvider = getPreferencesProvider(); - if (preferencesProvider == null) - { - return null; - } - Map<String, Object> preferences = preferencesProvider.deletePreferences(this.getName()); - preferencesProvider.setPreferences(this.getName(), newPreferences); - return preferences; - } - - private PreferencesProvider getPreferencesProvider() - { - return PrincipalDatabaseAuthenticationManagerAdapter.this.getPreferencesProvider(); - } - - } - - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java deleted file mode 100644 index 71bc3c631d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider; -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; -import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager; -import org.apache.qpid.server.model.adapter.AuthenticationProviderAdapter.PrincipalDatabaseAuthenticationManagerAdapter; -import org.apache.qpid.server.model.adapter.AuthenticationProviderAdapter.SimpleAuthenticationProviderAdapter; - -public class AuthenticationProviderFactory -{ - private final Iterable<AuthenticationManagerFactory> _factories; - private Collection<String> _supportedAuthenticationProviders; - private final PreferencesProviderCreator _preferencesProviderCreator; - - public AuthenticationProviderFactory(QpidServiceLoader<AuthenticationManagerFactory> authManagerFactoryServiceLoader, PreferencesProviderCreator preferencesProviderCreator) - { - _preferencesProviderCreator = preferencesProviderCreator; - _factories = authManagerFactoryServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class); - List<String> supportedAuthenticationProviders = new ArrayList<String>(); - for (AuthenticationManagerFactory factory : _factories) - { - supportedAuthenticationProviders.add(factory.getType()); - } - _supportedAuthenticationProviders = Collections.unmodifiableCollection(supportedAuthenticationProviders); - } - - /** - * Creates {@link AuthenticationProvider} for given ID, {@link Broker} and attributes. - * <p> - * The configured {@link AuthenticationManagerFactory}'s are used to try to create the {@link AuthenticationProvider}. - * The first non-null instance is returned. The factories are used in non-deterministic order. - */ - public AuthenticationProvider create(UUID id, Broker broker, Map<String, Object> attributes) - { - AuthenticationProviderAdapter<?> provider = createAuthenticationProvider(id, broker, attributes); - provider.getAuthManager().onCreate(); - return provider; - } - - /** - * Recovers {@link AuthenticationProvider} for given ID, attributes and {@link Broker}. - * <p> - * The configured {@link AuthenticationManagerFactory}'s are used to try to create the {@link AuthenticationProvider}. - * The first non-null instance is returned. The factories are used in non-deterministic order. - */ - public AuthenticationProvider recover(UUID id, Map<String, Object> attributes, Broker broker) - { - return createAuthenticationProvider(id, broker, attributes); - } - - private AuthenticationProviderAdapter<?> createAuthenticationProvider(UUID id, Broker broker, Map<String, Object> attributes) - { - for (AuthenticationManagerFactory factory : _factories) - { - AuthenticationManager manager = factory.createInstance(attributes); - if (manager != null) - { - AuthenticationProviderAdapter<?> authenticationProvider; - if (manager instanceof PrincipalDatabaseAuthenticationManager) - { - authenticationProvider = new PrincipalDatabaseAuthenticationManagerAdapter(id, broker, - (PrincipalDatabaseAuthenticationManager) manager, attributes, factory.getAttributeNames(), _preferencesProviderCreator); - } - else - { - authenticationProvider = new SimpleAuthenticationProviderAdapter(id, broker, manager, attributes, factory.getAttributeNames(), _preferencesProviderCreator); - } - return authenticationProvider; - } - } - - throw new IllegalArgumentException("No authentication provider factory found for configuration attributes " + attributes); - } - - public Collection<String> getSupportedAuthenticationProviders() - { - return _supportedAuthenticationProviders; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java deleted file mode 100644 index 92b8f55f23..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.qpid.AMQInternalException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.server.model.Binding; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Exchange; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; - -final class BindingAdapter extends AbstractAdapter implements Binding -{ - private final org.apache.qpid.server.binding.Binding _binding; - private Statistics _statistics = NoStatistics.getInstance(); - private final ExchangeAdapter _exchange; - private QueueAdapter _queue; - - public BindingAdapter(final org.apache.qpid.server.binding.Binding binding, - ExchangeAdapter exchangeAdapter, - QueueAdapter queueAdapter) - { - super(binding.getId(), queueAdapter.getTaskExecutor()); - _binding = binding; - _exchange = exchangeAdapter; - _queue = queueAdapter; - addParent(Queue.class, queueAdapter); - addParent(Exchange.class, exchangeAdapter); - } - - - public ExchangeAdapter getExchange() - { - return _exchange; - } - - public QueueAdapter getQueue() - { - return _queue; - } - - public String getName() - { - return _binding.getBindingKey(); - } - - public String setName(final String currentName, final String desiredName) - throws IllegalStateException, AccessControlException - { - return null; //TODO - } - - public State getActualState() - { - return null; //TODO - } - - public boolean isDurable() - { - return _binding.getQueue().isDurable() && _binding.getExchange().isDurable(); - } - - public void setDurable(final boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - //TODO - } - - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - public LifetimePolicy setLifetimePolicy(final LifetimePolicy expected, final LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return null; //TODO - } - - public long getTimeToLive() - { - return 0; //TODO - } - - public long setTimeToLive(final long expected, final long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return 0; //TODO - } - - public Statistics getStatistics() - { - return _statistics; - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - return Collections.emptySet(); - } - - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - throw new IllegalArgumentException("Cannot add children to a binding"); - } - - public Map<String, Object> getArguments() - { - return new HashMap<String, Object> (_binding.getArguments()); - } - - public void delete() - { - try - { - _exchange.getExchange().removeBinding(_binding); - } - catch(AMQSecurityException e) - { - throw new AccessControlException(e.getMessage()); - } - catch(AMQInternalException e) - { - throw new IllegalStateException(e); - } - } - - @Override - public Object getAttribute(final String name) - { - if(ID.equals(name)) - { - return getId(); - } - else if(NAME.equals(name)) - { - return getName(); - } - else if(STATE.equals(name)) - { - - } - else if(DURABLE.equals(name)) - { - return _queue.isDurable() && _exchange.isDurable(); - } - else if(LIFETIME_POLICY.equals(name)) - { - return _queue.getLifetimePolicy() == LifetimePolicy.AUTO_DELETE || _exchange.getLifetimePolicy() == LifetimePolicy.AUTO_DELETE ? LifetimePolicy.AUTO_DELETE : LifetimePolicy.PERMANENT; - } - else if(TIME_TO_LIVE.equals(name)) - { - - } - else if(CREATED.equals(name)) - { - - } - else if(UPDATED.equals(name)) - { - - } - else if(EXCHANGE.equals(name)) - { - return _exchange.getName(); - } - else if(QUEUE.equals(name)) - { - return _queue.getName(); - } - else if(ARGUMENTS.equals(name)) - { - return getArguments(); - } - - return super.getAttribute(name); //TODO - } - - @Override - public Collection<String> getAttributeNames() - { - return Binding.AVAILABLE_ATTRIBUTES; - } - - @Override - protected boolean setState(State currentState, State desiredState) throws IllegalStateTransitionException, - AccessControlException - { - if (desiredState == State.DELETED) - { - delete(); - return true; - } - return false; - } - - @Override - public Object setAttribute(final String name, final Object expected, final Object desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on binding is not supported."); - } - - @Override - public void setAttributes(final Map<String, Object> attributes) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on binding is not supported."); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java deleted file mode 100644 index aec78ba414..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java +++ /dev/null @@ -1,1267 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.lang.reflect.Type; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.log4j.Logger; -import org.apache.qpid.common.QpidProperties; -import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.logging.LogRecorder; -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.actors.BrokerActor; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.BrokerMessages; -import org.apache.qpid.server.model.AccessControlProvider; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfigurationChangeListener; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.GroupProvider; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Model; -import org.apache.qpid.server.model.Plugin; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.model.adapter.AuthenticationProviderAdapter.SimpleAuthenticationProviderAdapter; -import org.apache.qpid.server.plugin.VirtualHostFactory; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.security.SubjectCreator; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; -import org.apache.qpid.server.security.auth.manager.SimpleAuthenticationManager; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.store.MessageStoreCreator; -import org.apache.qpid.server.util.MapValueConverter; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; - -public class BrokerAdapter extends AbstractAdapter implements Broker, ConfigurationChangeListener -{ - private static final Logger LOGGER = Logger.getLogger(BrokerAdapter.class); - - @SuppressWarnings("serial") - public static final Map<String, Type> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Type>(){{ - put(QUEUE_ALERT_THRESHOLD_MESSAGE_AGE, Long.class); - put(QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, Long.class); - put(QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES, Long.class); - put(QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE, Long.class); - put(QUEUE_ALERT_REPEAT_GAP, Long.class); - put(QUEUE_FLOW_CONTROL_SIZE_BYTES, Long.class); - put(QUEUE_FLOW_CONTROL_RESUME_SIZE_BYTES, Long.class); - put(VIRTUALHOST_HOUSEKEEPING_CHECK_PERIOD, Long.class); - - put(QUEUE_DEAD_LETTER_QUEUE_ENABLED, Boolean.class); - put(STATISTICS_REPORTING_RESET_ENABLED, Boolean.class); - - put(QUEUE_MAXIMUM_DELIVERY_ATTEMPTS, Integer.class); - put(CONNECTION_SESSION_COUNT_LIMIT, Integer.class); - put(CONNECTION_HEART_BEAT_DELAY, Integer.class); - put(CONNECTION_CLOSE_WHEN_NO_ROUTE, Boolean.class); - put(STATISTICS_REPORTING_PERIOD, Integer.class); - - put(NAME, String.class); - put(DEFAULT_VIRTUAL_HOST, String.class); - - put(VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE, Long.class); - put(VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_WARN, Long.class); - put(VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE, Long.class); - put(VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_WARN, Long.class); - put(MODEL_VERSION, String.class); - put(STORE_VERSION, String.class); - }}); - - public static final int DEFAULT_STATISTICS_REPORTING_PERIOD = 0; - public static final boolean DEFAULT_STATISTICS_REPORTING_RESET_ENABLED = false; - public static final long DEFAULT_ALERT_REPEAT_GAP = 30000l; - public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_AGE = 0l; - public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_COUNT = 0l; - public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_SIZE = 0l; - public static final long DEFAULT_ALERT_THRESHOLD_QUEUE_DEPTH = 0l; - public static final boolean DEFAULT_DEAD_LETTER_QUEUE_ENABLED = false; - public static final int DEFAULT_MAXIMUM_DELIVERY_ATTEMPTS = 0; - public static final long DEFAULT_FLOW_CONTROL_RESUME_SIZE_BYTES = 0l; - public static final long DEFAULT_FLOW_CONTROL_SIZE_BYTES = 0l; - public static final long DEFAULT_HOUSEKEEPING_CHECK_PERIOD = 30000l; - public static final int DEFAULT_HEART_BEAT_DELAY = 0; - public static final int DEFAULT_SESSION_COUNT_LIMIT = 256; - public static final String DEFAULT_NAME = "QpidBroker"; - public static final long DEFAULT_STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE = 0l; - public static final long DEFAULT_STORE_TRANSACTION_IDLE_TIMEOUT_WARN = 0l; - public static final long DEFAULT_STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE = 0l; - public static final long DEFAULT_STORE_TRANSACTION_OPEN_TIMEOUT_WARN = 0l; - public static final boolean DEFAULT_CONNECTION_CLOSE_WHEN_NO_ROUTE = true; - - @SuppressWarnings("serial") - private static final Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>(){{ - put(Broker.STATISTICS_REPORTING_PERIOD, DEFAULT_STATISTICS_REPORTING_PERIOD); - put(Broker.STATISTICS_REPORTING_RESET_ENABLED, DEFAULT_STATISTICS_REPORTING_RESET_ENABLED); - put(Broker.QUEUE_ALERT_REPEAT_GAP, DEFAULT_ALERT_REPEAT_GAP); - put(Broker.QUEUE_ALERT_THRESHOLD_MESSAGE_AGE, DEFAULT_ALERT_THRESHOLD_MESSAGE_AGE); - put(Broker.QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, DEFAULT_ALERT_THRESHOLD_MESSAGE_COUNT); - put(Broker.QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE, DEFAULT_ALERT_THRESHOLD_MESSAGE_SIZE); - put(Broker.QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES, DEFAULT_ALERT_THRESHOLD_QUEUE_DEPTH); - put(Broker.QUEUE_DEAD_LETTER_QUEUE_ENABLED, DEFAULT_DEAD_LETTER_QUEUE_ENABLED); - put(Broker.QUEUE_MAXIMUM_DELIVERY_ATTEMPTS, DEFAULT_MAXIMUM_DELIVERY_ATTEMPTS); - put(Broker.QUEUE_FLOW_CONTROL_RESUME_SIZE_BYTES, DEFAULT_FLOW_CONTROL_RESUME_SIZE_BYTES); - put(Broker.QUEUE_FLOW_CONTROL_SIZE_BYTES, DEFAULT_FLOW_CONTROL_SIZE_BYTES); - put(Broker.VIRTUALHOST_HOUSEKEEPING_CHECK_PERIOD, DEFAULT_HOUSEKEEPING_CHECK_PERIOD); - put(Broker.CONNECTION_HEART_BEAT_DELAY, DEFAULT_HEART_BEAT_DELAY); - put(Broker.CONNECTION_SESSION_COUNT_LIMIT, DEFAULT_SESSION_COUNT_LIMIT); - put(Broker.CONNECTION_CLOSE_WHEN_NO_ROUTE, DEFAULT_CONNECTION_CLOSE_WHEN_NO_ROUTE); - put(Broker.NAME, DEFAULT_NAME); - put(Broker.VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE, DEFAULT_STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE); - put(Broker.VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_WARN, DEFAULT_STORE_TRANSACTION_IDLE_TIMEOUT_WARN); - put(Broker.VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE, DEFAULT_STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE); - put(Broker.VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_WARN, DEFAULT_STORE_TRANSACTION_OPEN_TIMEOUT_WARN); - }}); - - private String[] POSITIVE_NUMERIC_ATTRIBUTES = { QUEUE_ALERT_THRESHOLD_MESSAGE_AGE, QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, - QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES, QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE, QUEUE_ALERT_REPEAT_GAP, QUEUE_FLOW_CONTROL_SIZE_BYTES, - QUEUE_FLOW_CONTROL_RESUME_SIZE_BYTES, QUEUE_MAXIMUM_DELIVERY_ATTEMPTS, VIRTUALHOST_HOUSEKEEPING_CHECK_PERIOD, CONNECTION_SESSION_COUNT_LIMIT, - CONNECTION_HEART_BEAT_DELAY, STATISTICS_REPORTING_PERIOD, VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE, - VIRTUALHOST_STORE_TRANSACTION_IDLE_TIMEOUT_WARN, VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE, - VIRTUALHOST_STORE_TRANSACTION_OPEN_TIMEOUT_WARN}; - - - private final StatisticsGatherer _statisticsGatherer; - private final VirtualHostRegistry _virtualHostRegistry; - private final LogRecorder _logRecorder; - private final RootMessageLogger _rootMessageLogger; - private StatisticsAdapter _statistics; - - private final Map<String, VirtualHost> _vhostAdapters = new HashMap<String, VirtualHost>(); - private final Map<UUID, Port> _portAdapters = new HashMap<UUID, Port>(); - private final Map<Port, Integer> _stillInUsePortNumbers = new HashMap<Port, Integer>(); - private final Map<UUID, AuthenticationProvider> _authenticationProviders = new HashMap<UUID, AuthenticationProvider>(); - private final Map<String, GroupProvider> _groupProviders = new HashMap<String, GroupProvider>(); - private final Map<UUID, ConfiguredObject> _plugins = new HashMap<UUID, ConfiguredObject>(); - private final Map<String, KeyStore> _keyStores = new HashMap<String, KeyStore>(); - private final Map<String, TrustStore> _trustStores = new HashMap<String, TrustStore>(); - private final Map<UUID, AccessControlProvider> _accessControlProviders = new HashMap<UUID, AccessControlProvider>(); - - private final GroupProviderFactory _groupProviderFactory; - private final AuthenticationProviderFactory _authenticationProviderFactory; - private final AccessControlProviderFactory _accessControlProviderFactory; - private final PreferencesProviderCreator _preferencesProviderCreator; - private final PortFactory _portFactory; - private final SecurityManager _securityManager; - - private final Collection<String> _supportedVirtualHostStoreTypes; - private Collection<String> _supportedBrokerStoreTypes; - private final ConfigurationEntryStore _brokerStore; - - private AuthenticationProvider _managementAuthenticationProvider; - private BrokerOptions _brokerOptions; - - public BrokerAdapter(UUID id, Map<String, Object> attributes, StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry, - LogRecorder logRecorder, RootMessageLogger rootMessageLogger, AuthenticationProviderFactory authenticationProviderFactory, - GroupProviderFactory groupProviderFactory, AccessControlProviderFactory accessControlProviderFactory, PortFactory portFactory, - PreferencesProviderCreator preferencesProviderCreatory, TaskExecutor taskExecutor, ConfigurationEntryStore brokerStore, BrokerOptions brokerOptions) - { - super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor); - _statisticsGatherer = statisticsGatherer; - _virtualHostRegistry = virtualHostRegistry; - _logRecorder = logRecorder; - _rootMessageLogger = rootMessageLogger; - _statistics = new StatisticsAdapter(statisticsGatherer); - _authenticationProviderFactory = authenticationProviderFactory; - _preferencesProviderCreator = preferencesProviderCreatory; - _groupProviderFactory = groupProviderFactory; - _accessControlProviderFactory = accessControlProviderFactory; - _portFactory = portFactory; - _brokerOptions = brokerOptions; - _securityManager = new SecurityManager(this, _brokerOptions.isManagementMode()); - _supportedVirtualHostStoreTypes = new MessageStoreCreator().getStoreTypes(); - _supportedBrokerStoreTypes = new BrokerConfigurationStoreCreator().getStoreTypes(); - _brokerStore = brokerStore; - if (_brokerOptions.isManagementMode()) - { - AuthenticationManager authManager = new SimpleAuthenticationManager(BrokerOptions.MANAGEMENT_MODE_USER_NAME, _brokerOptions.getManagementModePassword()); - AuthenticationProvider authenticationProvider = new SimpleAuthenticationProviderAdapter(UUID.randomUUID(), this, - authManager, Collections.<String, Object> emptyMap(), Collections.<String> emptySet(), _preferencesProviderCreator); - _managementAuthenticationProvider = authenticationProvider; - } - } - - public Collection<VirtualHost> getVirtualHosts() - { - synchronized(_vhostAdapters) - { - return new ArrayList<VirtualHost>(_vhostAdapters.values()); - } - } - - public Collection<Port> getPorts() - { - synchronized (_portAdapters) - { - final ArrayList<Port> ports = new ArrayList<Port>(_portAdapters.values()); - return ports; - } - } - - public Collection<AuthenticationProvider> getAuthenticationProviders() - { - synchronized (_authenticationProviders) - { - return new ArrayList<AuthenticationProvider>(_authenticationProviders.values()); - } - } - - public AuthenticationProvider findAuthenticationProviderByName(String authenticationProviderName) - { - if (isManagementMode()) - { - return _managementAuthenticationProvider; - } - Collection<AuthenticationProvider> providers = getAuthenticationProviders(); - for (AuthenticationProvider authenticationProvider : providers) - { - if (authenticationProvider.getName().equals(authenticationProviderName)) - { - return authenticationProvider; - } - } - return null; - } - - public KeyStore findKeyStoreByName(String keyStoreName) - { - synchronized(_keyStores) - { - return _keyStores.get(keyStoreName); - } - } - - public TrustStore findTrustStoreByName(String trustStoreName) - { - synchronized(_trustStores) - { - return _trustStores.get(trustStoreName); - } - } - - @Override - public Collection<GroupProvider> getGroupProviders() - { - synchronized (_groupProviders) - { - final ArrayList<GroupProvider> groupManagers = - new ArrayList<GroupProvider>(_groupProviders.values()); - return groupManagers; - } - } - - private VirtualHost createVirtualHost(final Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException - { - final VirtualHostAdapter virtualHostAdapter = new VirtualHostAdapter(UUID.randomUUID(), attributes, this, - _statisticsGatherer, getTaskExecutor()); - addVirtualHost(virtualHostAdapter); - - // permission has already been granted to create the virtual host - // disable further access check on other operations, e.g. create exchange - SecurityManager.setAccessChecksDisabled(true); - try - { - virtualHostAdapter.setDesiredState(State.INITIALISING, State.ACTIVE); - } - finally - { - SecurityManager.setAccessChecksDisabled(false); - } - return virtualHostAdapter; - } - - private boolean deleteVirtualHost(final VirtualHost vhost) throws AccessControlException, IllegalStateException - { - synchronized (_vhostAdapters) - { - _vhostAdapters.remove(vhost.getName()); - } - vhost.removeChangeListener(this); - return true; - } - - public String getName() - { - return (String)getAttribute(NAME); - } - - public String setName(final String currentName, final String desiredName) - throws IllegalStateException, AccessControlException - { - return null; //TODO - } - - - public State getActualState() - { - return null; //TODO - } - - - public boolean isDurable() - { - return true; - } - - public void setDurable(final boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - public LifetimePolicy setLifetimePolicy(final LifetimePolicy expected, final LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - public long getTimeToLive() - { - return 0; - } - - public long setTimeToLive(final long expected, final long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - public Statistics getStatistics() - { - return _statistics; - } - - @SuppressWarnings("unchecked") - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if(clazz == VirtualHost.class) - { - return (Collection<C>) getVirtualHosts(); - } - else if(clazz == Port.class) - { - return (Collection<C>) getPorts(); - } - else if(clazz == AccessControlProvider.class) - { - return (Collection<C>) getAccessControlProviders(); - } - else if(clazz == AuthenticationProvider.class) - { - return (Collection<C>) getAuthenticationProviders(); - } - else if(clazz == GroupProvider.class) - { - return (Collection<C>) getGroupProviders(); - } - else if(clazz == KeyStore.class) - { - return (Collection<C>) getKeyStores(); - } - else if(clazz == TrustStore.class) - { - return (Collection<C>) getTrustStores(); - } - else if(clazz == Plugin.class) - { - return (Collection<C>) getPlugins(); - } - - return Collections.emptySet(); - } - - @SuppressWarnings("unchecked") - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - if(childClass == VirtualHost.class) - { - return (C) createVirtualHost(attributes); - } - else if(childClass == Port.class) - { - return (C) createPort(attributes); - } - else if(childClass == AccessControlProvider.class) - { - return (C) createAccessControlProvider(attributes); - } - else if(childClass == AuthenticationProvider.class) - { - return (C) createAuthenticationProvider(attributes); - } - else if(childClass == KeyStore.class) - { - return (C) createKeyStore(attributes); - } - else if(childClass == TrustStore.class) - { - return (C) createTrustStore(attributes); - } - else if(childClass == GroupProvider.class) - { - return (C) createGroupProvider(attributes); - } - else - { - throw new IllegalArgumentException("Cannot create child of class " + childClass.getSimpleName()); - } - } - - /** - * Called when adding a new port via the management interface - */ - private Port createPort(Map<String, Object> attributes) - { - Port port = _portFactory.createPort(UUID.randomUUID(), this, attributes); - addPort(port); - - //1. AMQP ports are disabled during ManagementMode. - //2. The management plugins can currently only start ports at broker startup and - // not when they are newly created via the management interfaces. - //3. When active ports are deleted, or their port numbers updated, the broker must be - // restarted for it to take effect so we can't reuse port numbers until it is. - boolean quiesce = isManagementMode() || !(port instanceof AmqpPortAdapter) || isPreviouslyUsedPortNumber(port); - - port.setDesiredState(State.INITIALISING, quiesce ? State.QUIESCED : State.ACTIVE); - - return port; - } - - private void addPort(Port port) - { - synchronized (_portAdapters) - { - int portNumber = port.getPort(); - String portName = port.getName(); - UUID portId = port.getId(); - - for(Port p : _portAdapters.values()) - { - if(portNumber == p.getPort()) - { - throw new IllegalConfigurationException("Can't add port " + portName + " because port number " + portNumber + " is already configured for port " + p.getName()); - } - - if(portName == p.getName()) - { - throw new IllegalConfigurationException("Can't add Port because one with name " + portName + " already exists"); - } - - if(portId == p.getId()) - { - throw new IllegalConfigurationException("Can't add Port because one with id " + portId + " already exists"); - } - } - - _portAdapters.put(port.getId(), port); - } - port.addChangeListener(this); - } - - private AccessControlProvider createAccessControlProvider(Map<String, Object> attributes) - { - AccessControlProvider accessControlProvider = null; - synchronized (_accessControlProviders) - { - accessControlProvider = _accessControlProviderFactory.create(UUID.randomUUID(), this, attributes); - addAccessControlProvider(accessControlProvider); - } - - boolean quiesce = isManagementMode() ; - accessControlProvider.setDesiredState(State.INITIALISING, quiesce ? State.QUIESCED : State.ACTIVE); - - return accessControlProvider; - } - - /** - * @throws IllegalConfigurationException if an AuthenticationProvider with the same name already exists - */ - private void addAccessControlProvider(AccessControlProvider accessControlProvider) - { - String name = accessControlProvider.getName(); - synchronized (_authenticationProviders) - { - if (_accessControlProviders.containsKey(accessControlProvider.getId())) - { - throw new IllegalConfigurationException("Can't add AccessControlProvider because one with id " + accessControlProvider.getId() + " already exists"); - } - for (AccessControlProvider provider : _accessControlProviders.values()) - { - if (provider.getName().equals(name)) - { - throw new IllegalConfigurationException("Can't add AccessControlProvider because one with name " + name + " already exists"); - } - } - _accessControlProviders.put(accessControlProvider.getId(), accessControlProvider); - } - - accessControlProvider.addChangeListener(this); - accessControlProvider.addChangeListener(_securityManager); - } - - private boolean deleteAccessControlProvider(AccessControlProvider accessControlProvider) - { - AccessControlProvider removedAccessControlProvider = null; - synchronized (_accessControlProviders) - { - removedAccessControlProvider = _accessControlProviders.remove(accessControlProvider.getId()); - } - - if(removedAccessControlProvider != null) - { - removedAccessControlProvider.removeChangeListener(this); - removedAccessControlProvider.removeChangeListener(_securityManager); - } - - return removedAccessControlProvider != null; - } - - private AuthenticationProvider createAuthenticationProvider(Map<String, Object> attributes) - { - AuthenticationProvider authenticationProvider = _authenticationProviderFactory.create(UUID.randomUUID(), this, attributes); - authenticationProvider.setDesiredState(State.INITIALISING, State.ACTIVE); - addAuthenticationProvider(authenticationProvider); - return authenticationProvider; - } - - /** - * @throws IllegalConfigurationException if an AuthenticationProvider with the same name already exists - */ - private void addAuthenticationProvider(AuthenticationProvider authenticationProvider) - { - String name = authenticationProvider.getName(); - synchronized (_authenticationProviders) - { - if (_authenticationProviders.containsKey(authenticationProvider.getId())) - { - throw new IllegalConfigurationException("Cannot add AuthenticationProvider because one with id " + authenticationProvider.getId() + " already exists"); - } - for (AuthenticationProvider provider : _authenticationProviders.values()) - { - if (provider.getName().equals(name)) - { - throw new IllegalConfigurationException("Cannot add AuthenticationProvider because one with name " + name + " already exists"); - } - } - _authenticationProviders.put(authenticationProvider.getId(), authenticationProvider); - } - authenticationProvider.addChangeListener(this); - } - - private GroupProvider createGroupProvider(Map<String, Object> attributes) - { - GroupProvider groupProvider = _groupProviderFactory.create(UUID.randomUUID(), this, attributes); - groupProvider.setDesiredState(State.INITIALISING, State.ACTIVE); - addGroupProvider(groupProvider); - return groupProvider; - } - - private void addGroupProvider(GroupProvider groupProvider) - { - synchronized (_groupProviders) - { - String name = groupProvider.getName(); - if(_groupProviders.containsKey(name)) - { - throw new IllegalConfigurationException("Cannot add GroupProvider because one with name " + name + " already exists"); - } - _groupProviders.put(name, groupProvider); - } - groupProvider.addChangeListener(this); - } - - private boolean deleteGroupProvider(GroupProvider groupProvider) - { - GroupProvider removedGroupProvider = null; - synchronized (_groupProviders) - { - removedGroupProvider = _groupProviders.remove(groupProvider.getName()); - } - - if(removedGroupProvider != null) - { - removedGroupProvider.removeChangeListener(this); - } - - return removedGroupProvider != null; - } - - private KeyStore createKeyStore(Map<String, Object> attributes) - { - KeyStore keyStore = new KeyStoreAdapter(UUIDGenerator.generateRandomUUID(), this, attributes); - addKeyStore(keyStore); - - return keyStore; - } - - private TrustStore createTrustStore(Map<String, Object> attributes) - { - TrustStore trustStore = new TrustStoreAdapter(UUIDGenerator.generateRandomUUID(), this, attributes); - addTrustStore(trustStore); - - return trustStore; - } - - private void addKeyStore(KeyStore keyStore) - { - synchronized (_keyStores) - { - if(_keyStores.containsKey(keyStore.getName())) - { - throw new IllegalConfigurationException("Can't add KeyStore because one with name " + keyStore.getName() + " already exists"); - } - _keyStores.put(keyStore.getName(), keyStore); - } - keyStore.addChangeListener(this); - } - - private boolean deleteKeyStore(KeyStore object) - { - synchronized(_keyStores) - { - String name = object.getName(); - KeyStore removedKeyStore = _keyStores.remove(name); - if(removedKeyStore != null) - { - removedKeyStore.removeChangeListener(this); - } - - return removedKeyStore != null; - } - } - - private void addTrustStore(TrustStore trustStore) - { - synchronized (_trustStores) - { - if(_trustStores.containsKey(trustStore.getName())) - { - throw new IllegalConfigurationException("Can't add TrustStore because one with name " + trustStore.getName() + " already exists"); - } - _trustStores.put(trustStore.getName(), trustStore); - } - trustStore.addChangeListener(this); - } - - private boolean deleteTrustStore(TrustStore object) - { - synchronized(_trustStores) - { - String name = object.getName(); - TrustStore removedTrustStore = _trustStores.remove(name); - if(removedTrustStore != null) - { - removedTrustStore.removeChangeListener(this); - } - - return removedTrustStore != null; - } - } - - @Override - public Collection<String> getAttributeNames() - { - return AVAILABLE_ATTRIBUTES; - } - - @Override - public Object getAttribute(String name) - { - if(ID.equals(name)) - { - return getId(); - } - else if(STATE.equals(name)) - { - return State.ACTIVE; - } - else if(DURABLE.equals(name)) - { - return isDurable(); - } - else if(LIFETIME_POLICY.equals(name)) - { - return LifetimePolicy.PERMANENT; - } - else if(TIME_TO_LIVE.equals(name)) - { - // TODO - } - else if(CREATED.equals(name)) - { - // TODO - } - else if(UPDATED.equals(name)) - { - // TODO - } - else if(BUILD_VERSION.equals(name)) - { - return QpidProperties.getBuildVersion(); - } - else if(BYTES_RETAINED.equals(name)) - { - // TODO - } - else if(OPERATING_SYSTEM.equals(name)) - { - return System.getProperty("os.name") + " " - + System.getProperty("os.version") + " " - + System.getProperty("os.arch"); - } - else if(PLATFORM.equals(name)) - { - return System.getProperty("java.vendor") + " " - + System.getProperty("java.runtime.version", System.getProperty("java.version")); - } - else if(PROCESS_PID.equals(name)) - { - // TODO - } - else if(PRODUCT_VERSION.equals(name)) - { - return QpidProperties.getReleaseVersion(); - } - else if(SUPPORTED_BROKER_STORE_TYPES.equals(name)) - { - return _supportedBrokerStoreTypes; - } - else if(SUPPORTED_VIRTUALHOST_STORE_TYPES.equals(name)) - { - return _supportedVirtualHostStoreTypes; - } - else if(SUPPORTED_VIRTUALHOST_TYPES.equals(name)) - { - return VirtualHostFactory.TYPES.get(); - } - else if(SUPPORTED_AUTHENTICATION_PROVIDERS.equals(name)) - { - return _authenticationProviderFactory.getSupportedAuthenticationProviders(); - } - else if (SUPPORTED_PREFERENCES_PROVIDERS_TYPES.equals(name)) - { - return _preferencesProviderCreator.getSupportedPreferencesProviders(); - } - else if (MODEL_VERSION.equals(name)) - { - return Model.MODEL_VERSION; - } - else if (STORE_VERSION.equals(name)) - { - return _brokerStore.getVersion(); - } - else if (STORE_TYPE.equals(name)) - { - return _brokerStore.getType(); - } - else if (STORE_PATH.equals(name)) - { - return _brokerStore.getStoreLocation(); - } - return super.getAttribute(name); - } - - private boolean deletePort(State oldState, Port portAdapter) - { - Port removedPort = null; - synchronized (_portAdapters) - { - removedPort = _portAdapters.remove(portAdapter.getId()); - } - - if (removedPort != null) - { - removedPort.removeChangeListener(this); - - if(oldState == State.ACTIVE) - { - //Record the originally used port numbers of previously-active ports being deleted, to ensure - //when creating new ports we don't try to re-bind a port number that we are currently still using - recordPreviouslyUsedPortNumberIfNecessary(removedPort, removedPort.getPort()); - } - } - - return removedPort != null; - } - - private boolean deleteAuthenticationProvider(AuthenticationProvider authenticationProvider) - { - AuthenticationProvider removedAuthenticationProvider = null; - synchronized (_authenticationProviders) - { - removedAuthenticationProvider = _authenticationProviders.remove(authenticationProvider.getId()); - } - - if(removedAuthenticationProvider != null) - { - removedAuthenticationProvider.removeChangeListener(this); - } - - return removedAuthenticationProvider != null; - } - - private void addVirtualHost(VirtualHost virtualHost) - { - synchronized (_vhostAdapters) - { - String name = virtualHost.getName(); - if (_vhostAdapters.containsKey(name)) - { - throw new IllegalConfigurationException("Virtual host with name " + name + " is already specified!"); - } - _vhostAdapters.put(name, virtualHost); - } - virtualHost.addChangeListener(this); - } - - @Override - public boolean setState(State currentState, State desiredState) - { - if (desiredState == State.ACTIVE) - { - changeState(_groupProviders, currentState, State.ACTIVE, false); - changeState(_authenticationProviders, currentState, State.ACTIVE, false); - changeState(_accessControlProviders, currentState, State.ACTIVE, false); - - CurrentActor.set(new BrokerActor(getRootMessageLogger())); - try - { - changeState(_vhostAdapters, currentState, State.ACTIVE, false); - } - finally - { - CurrentActor.remove(); - } - - changeState(_portAdapters, currentState,State.ACTIVE, false); - changeState(_plugins, currentState,State.ACTIVE, false); - - if (isManagementMode()) - { - CurrentActor.get().message(BrokerMessages.MANAGEMENT_MODE(BrokerOptions.MANAGEMENT_MODE_USER_NAME, _brokerOptions.getManagementModePassword())); - } - return true; - } - else if (desiredState == State.STOPPED) - { - changeState(_plugins, currentState,State.STOPPED, true); - changeState(_portAdapters, currentState, State.STOPPED, true); - changeState(_vhostAdapters,currentState, State.STOPPED, true); - changeState(_authenticationProviders, currentState, State.STOPPED, true); - changeState(_groupProviders, currentState, State.STOPPED, true); - return true; - } - return false; - } - - private void changeState(Map<?, ? extends ConfiguredObject> configuredObjectMap, State currentState, State desiredState, boolean swallowException) - { - synchronized(configuredObjectMap) - { - Collection<? extends ConfiguredObject> adapters = configuredObjectMap.values(); - for (ConfiguredObject configuredObject : adapters) - { - if (State.ACTIVE.equals(desiredState) && State.QUIESCED.equals(configuredObject.getActualState())) - { - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug(configuredObject + " cannot be activated as it is " +State.QUIESCED); - } - continue; - } - try - { - configuredObject.setDesiredState(currentState, desiredState); - } - catch(RuntimeException e) - { - if (swallowException) - { - LOGGER.error("Failed to stop " + configuredObject, e); - } - else - { - throw e; - } - } - } - } - } - - @Override - public void stateChanged(ConfiguredObject object, State oldState, State newState) - { - if(newState == State.DELETED) - { - boolean childDeleted = false; - if(object instanceof AuthenticationProvider) - { - childDeleted = deleteAuthenticationProvider((AuthenticationProvider)object); - } - else if(object instanceof AccessControlProvider) - { - childDeleted = deleteAccessControlProvider((AccessControlProvider)object); - } - else if(object instanceof Port) - { - childDeleted = deletePort(oldState, (Port)object); - } - else if(object instanceof VirtualHost) - { - childDeleted = deleteVirtualHost((VirtualHost)object); - } - else if(object instanceof GroupProvider) - { - childDeleted = deleteGroupProvider((GroupProvider)object); - } - else if(object instanceof KeyStore) - { - childDeleted = deleteKeyStore((KeyStore)object); - } - else if(object instanceof TrustStore) - { - childDeleted = deleteTrustStore((TrustStore)object); - } - - if(childDeleted) - { - childRemoved(object); - } - } - } - - @Override - public void childAdded(ConfiguredObject object, ConfiguredObject child) - { - // no-op - } - - @Override - public void childRemoved(ConfiguredObject object, ConfiguredObject child) - { - // no-op - } - - @Override - public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue) - { - if(object instanceof Port) - { - //Record all the originally used port numbers of active ports, to ensure that when - //creating new ports we don't try to re-bind a port number that we are still using - if(attributeName == Port.PORT && object.getActualState() == State.ACTIVE) - { - recordPreviouslyUsedPortNumberIfNecessary((Port) object, (Integer)oldAttributeValue); - } - } - } - - private void addPlugin(ConfiguredObject plugin) - { - synchronized(_plugins) - { - if (_plugins.containsKey(plugin.getId())) - { - throw new IllegalConfigurationException("Plugin with id '" + plugin.getId() + "' is already registered!"); - } - _plugins.put(plugin.getId(), plugin); - } - plugin.addChangeListener(this); - } - - - private Collection<ConfiguredObject> getPlugins() - { - synchronized(_plugins) - { - return Collections.unmodifiableCollection(_plugins.values()); - } - } - - public void recoverChild(ConfiguredObject object) - { - if(object instanceof AuthenticationProvider) - { - addAuthenticationProvider((AuthenticationProvider)object); - } - else if(object instanceof AccessControlProvider) - { - addAccessControlProvider((AccessControlProvider)object); - } - else if(object instanceof Port) - { - addPort((Port)object); - } - else if(object instanceof VirtualHost) - { - addVirtualHost((VirtualHost)object); - } - else if(object instanceof GroupProvider) - { - addGroupProvider((GroupProvider)object); - } - else if(object instanceof KeyStore) - { - addKeyStore((KeyStore)object); - } - else if(object instanceof TrustStore) - { - addTrustStore((TrustStore)object); - } - else if(object instanceof Plugin) - { - addPlugin(object); - } - else - { - throw new IllegalArgumentException("Attempted to recover unexpected type of configured object: " + object.getClass().getName()); - } - } - - @Override - public RootMessageLogger getRootMessageLogger() - { - return _rootMessageLogger; - } - - @Override - public SecurityManager getSecurityManager() - { - return _securityManager; - } - - @Override - public LogRecorder getLogRecorder() - { - return _logRecorder; - } - - @Override - public VirtualHost findVirtualHostByName(String name) - { - return _vhostAdapters.get(name); - } - - @Override - public SubjectCreator getSubjectCreator(SocketAddress localAddress) - { - AuthenticationProvider provider = getAuthenticationProvider(localAddress); - - if(provider == null) - { - throw new IllegalConfigurationException("Unable to determine authentication provider for address: " + localAddress); - } - - return provider.getSubjectCreator(); - } - - @Override - public AuthenticationProvider getAuthenticationProvider(SocketAddress localAddress) - { - InetSocketAddress inetSocketAddress = (InetSocketAddress)localAddress; - AuthenticationProvider provider = null; - Collection<Port> ports = getPorts(); - for (Port p : ports) - { - if (inetSocketAddress.getPort() == p.getPort()) - { - provider = p.getAuthenticationProvider(); - break; - } - } - return provider; - } - - @Override - public Collection<KeyStore> getKeyStores() - { - synchronized(_keyStores) - { - return Collections.unmodifiableCollection(_keyStores.values()); - } - } - - @Override - public Collection<TrustStore> getTrustStores() - { - synchronized(_trustStores) - { - return Collections.unmodifiableCollection(_trustStores.values()); - } - } - - @Override - public VirtualHostRegistry getVirtualHostRegistry() - { - return _virtualHostRegistry; - } - - @Override - public TaskExecutor getTaskExecutor() - { - return super.getTaskExecutor(); - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - Map<String, Object> convertedAttributes = MapValueConverter.convert(attributes, ATTRIBUTE_TYPES); - validateAttributes(convertedAttributes); - - super.changeAttributes(convertedAttributes); - } - - private void validateAttributes(Map<String, Object> convertedAttributes) - { - if (convertedAttributes.containsKey(MODEL_VERSION) && !Model.MODEL_VERSION.equals(convertedAttributes.get(MODEL_VERSION))) - { - throw new IllegalConfigurationException("Cannot change the model version"); - } - - if (convertedAttributes.containsKey(STORE_VERSION) - && !new Integer(_brokerStore.getVersion()).equals(convertedAttributes.get(STORE_VERSION))) - { - throw new IllegalConfigurationException("Cannot change the store version"); - } - - String defaultVirtualHost = (String) convertedAttributes.get(DEFAULT_VIRTUAL_HOST); - if (defaultVirtualHost != null) - { - VirtualHost foundHost = findVirtualHostByName(defaultVirtualHost); - if (foundHost == null) - { - throw new IllegalConfigurationException("Virtual host with name " + defaultVirtualHost - + " cannot be set as a default as it does not exist"); - } - } - Long queueFlowControlSize = (Long) convertedAttributes.get(QUEUE_FLOW_CONTROL_SIZE_BYTES); - Long queueFlowControlResumeSize = (Long) convertedAttributes.get(QUEUE_FLOW_CONTROL_RESUME_SIZE_BYTES); - if (queueFlowControlSize != null || queueFlowControlResumeSize != null ) - { - if (queueFlowControlSize == null) - { - queueFlowControlSize = (Long)getAttribute(QUEUE_FLOW_CONTROL_SIZE_BYTES); - } - if (queueFlowControlResumeSize == null) - { - queueFlowControlResumeSize = (Long)getAttribute(QUEUE_FLOW_CONTROL_RESUME_SIZE_BYTES); - } - if (queueFlowControlResumeSize > queueFlowControlSize) - { - throw new IllegalConfigurationException("Flow resume size can't be greater than flow control size"); - } - } - for (String attributeName : POSITIVE_NUMERIC_ATTRIBUTES) - { - Number value = (Number) convertedAttributes.get(attributeName); - if (value != null && value.longValue() < 0) - { - throw new IllegalConfigurationException("Only positive integer value can be specified for the attribute " - + attributeName); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_securityManager.authoriseConfiguringBroker(getName(), Broker.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of broker attributes is denied"); - } - } - - @Override - protected <C extends ConfiguredObject> void authoriseCreateChild(Class<C> childClass, Map<String, Object> attributes, - ConfiguredObject... otherParents) throws AccessControlException - { - if (!_securityManager.authoriseConfiguringBroker(String.valueOf(attributes.get(NAME)), childClass, Operation.CREATE)) - { - throw new AccessControlException("Creation of new broker level entity is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_securityManager.authoriseConfiguringBroker(getName(), Broker.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of broker attributes is denied"); - } - } - - @Override - public boolean isManagementMode() - { - return _brokerOptions.isManagementMode(); - } - - @Override - public Collection<AccessControlProvider> getAccessControlProviders() - { - synchronized (_accessControlProviders) - { - return new ArrayList<AccessControlProvider>(_accessControlProviders.values()); - } - } - - private void recordPreviouslyUsedPortNumberIfNecessary(Port port, Integer portNumber) - { - //If we haven't previously recorded its original port number, record it now - if(!_stillInUsePortNumbers.containsKey(port)) - { - _stillInUsePortNumbers.put(port, portNumber); - } - } - - private boolean isPreviouslyUsedPortNumber(Port port) - { - return _stillInUsePortNumbers.containsValue(port.getPort()); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java deleted file mode 100644 index e8bacb2712..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.qpid.AMQException; -import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Connection; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Session; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.protocol.AMQConnectionModel; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.stats.StatisticsGatherer; - -final class ConnectionAdapter extends AbstractAdapter implements Connection -{ - private AMQConnectionModel _connection; - - private final Map<AMQSessionModel, SessionAdapter> _sessionAdapters = - new HashMap<AMQSessionModel, SessionAdapter>(); - private final Statistics _statistics; - - public ConnectionAdapter(final AMQConnectionModel conn, TaskExecutor taskExecutor) - { - super(UUIDGenerator.generateRandomUUID(), taskExecutor); - _connection = conn; - _statistics = new ConnectionStatisticsAdapter(conn); - } - - public Collection<Session> getSessions() - { - List<AMQSessionModel> actualSessions = _connection.getSessionModels(); - - synchronized (_sessionAdapters) - { - Iterator<AMQSessionModel> iterator = _sessionAdapters.keySet().iterator(); - while(iterator.hasNext()) - { - AMQSessionModel session = iterator.next(); - if(!actualSessions.contains(session)) - { - SessionAdapter adapter = _sessionAdapters.get(session); - iterator.remove(); - - childRemoved(adapter); // Trigger corresponding ConfigurationChangeListener childRemoved() callback. - } - } - - for(AMQSessionModel session : actualSessions) - { - if(!_sessionAdapters.containsKey(session)) - { - SessionAdapter adapter = new SessionAdapter(session, getTaskExecutor()); - _sessionAdapters.put(session, adapter); - childAdded(adapter); // Trigger corresponding ConfigurationChangeListener childAdded() callback. - } - } - - return new ArrayList<Session>(_sessionAdapters.values()); - } - } - - /** - * Retrieve the SessionAdapter instance keyed by the AMQSessionModel from this Connection. - * @param session the AMQSessionModel used to index the SessionAdapter. - * @return the requested SessionAdapter. - */ - SessionAdapter getSessionAdapter(AMQSessionModel session) - { - synchronized (_sessionAdapters) - { - getSessions(); // Call getSessions() first to ensure _sessionAdapters state is up to date with actualSessions. - return _sessionAdapters.get(session); - } - } - - public void delete() - { - try - { - _connection.close(AMQConstant.CONNECTION_FORCED, "Connection closed by external action"); - } - catch(AMQException e) - { - throw new IllegalStateException(e); - } - } - - public String getName() - { - final String remoteAddressString = _connection.getRemoteAddressString(); - return remoteAddressString.replaceAll("/",""); - } - - public String setName(final String currentName, final String desiredName) - throws IllegalStateException, AccessControlException - { - return null; //TODO - } - - public State getActualState() - { - return null; //TODO - } - - public boolean isDurable() - { - return false; //TODO - } - - public void setDurable(final boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - //TODO - } - - public LifetimePolicy getLifetimePolicy() - { - return null; //TODO - } - - public LifetimePolicy setLifetimePolicy(final LifetimePolicy expected, final LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return null; //TODO - } - - public long getTimeToLive() - { - return 0; //TODO - } - - public long setTimeToLive(final long expected, final long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return 0; //TODO - } - - @Override - public Object getAttribute(String name) - { - - if(name.equals(ID)) - { - return getId(); - } - else if (name.equals(NAME)) - { - return getName(); - } - else if(name.equals(CLIENT_ID)) - { - return _connection.getClientId(); - } - else if(name.equals(CLIENT_VERSION)) - { - return _connection.getClientVersion(); - } - else if(name.equals(INCOMING)) - { - return true; - } - else if(name.equals(LOCAL_ADDRESS)) - { - - } - else if(name.equals(PRINCIPAL)) - { - return _connection.getPrincipalAsString(); - } - else if(name.equals(PROPERTIES)) - { - - } - else if(name.equals(REMOTE_ADDRESS)) - { - return _connection.getRemoteAddressString(); - } - else if(name.equals(REMOTE_PROCESS_NAME)) - { - - } - else if(name.equals(REMOTE_PROCESS_PID)) - { - - } - else if(name.equals(SESSION_COUNT_LIMIT)) - { - return _connection.getSessionCountLimit(); - } - else if(name.equals(TRANSPORT)) - { - return String.valueOf(_connection.getTransport()); - } - else if(name.equals(PORT)) - { - return String.valueOf(_connection.getPort()); - } - return super.getAttribute(name); - } - - @Override - public Collection<String> getAttributeNames() - { - final HashSet<String> attrNames = new HashSet<String>(super.getAttributeNames()); - attrNames.addAll(Connection.AVAILABLE_ATTRIBUTES); - return Collections.unmodifiableCollection(attrNames); - } - - public Statistics getStatistics() - { - return _statistics; - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if(clazz == Session.class) - { - return (Collection<C>) getSessions(); - } - else - { - return Collections.emptySet(); - } - } - - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - if(childClass == Session.class) - { - throw new IllegalStateException(); - } - else - { - throw new IllegalArgumentException("Cannot create a child of class " + childClass.getSimpleName()); - } - - } - - private class ConnectionStatisticsAdapter extends StatisticsAdapter - { - public ConnectionStatisticsAdapter(StatisticsGatherer applicationRegistry) - { - super(applicationRegistry); - } - - @Override - public Collection<String> getStatisticNames() - { - return Connection.AVAILABLE_STATISTICS; - } - - @Override - public Object getStatistic(String name) - { - if(LAST_IO_TIME.equals(name)) - { - return _connection.getLastIoTime(); - } - else if(SESSION_COUNT.equals(name)) - { - return _connection.getSessionModels().size(); - } - return super.getStatistic(name); - } - } - - @Override - protected boolean setState(State currentState, State desiredState) - { - // TODO: add state management - return false; - } - - @Override - public Object setAttribute(final String name, final Object expected, final Object desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on connection is not supported."); - } - - @Override - public void setAttributes(final Map<String, Object> attributes) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on connection is not supported."); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java deleted file mode 100644 index 696c59783e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.util.Map; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Consumer; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.subscription.Subscription; - -import java.security.AccessControlException; -import java.util.Collection; -import java.util.Collections; - -public class ConsumerAdapter extends AbstractAdapter implements Consumer -{ - private final Subscription _subscription; - private final QueueAdapter _queue; - private final SessionAdapter _session; - private final ConsumerStatistics _statistics; - - public ConsumerAdapter(final QueueAdapter queueAdapter, final SessionAdapter sessionAdapter, - final Subscription subscription) - { - super(UUIDGenerator.generateConsumerUUID(queueAdapter.getVirtualHost().getName(), - queueAdapter.getName(), - subscription.getSessionModel().getConnectionModel().getRemoteAddressString(), - String.valueOf(subscription.getSessionModel().getChannelId()), - subscription.getConsumerName()), queueAdapter.getTaskExecutor()); - _subscription = subscription; - _queue = queueAdapter; - _session = sessionAdapter; - _statistics = new ConsumerStatistics(); - //TODO - } - - public String getName() - { - return _subscription.getConsumerName(); - } - - public String setName(final String currentName, final String desiredName) - throws IllegalStateException, AccessControlException - { - return null; //TODO - } - - public State getActualState() - { - return null; //TODO - } - - public boolean isDurable() - { - return false; //TODO - } - - public void setDurable(final boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - //TODO - } - - public LifetimePolicy getLifetimePolicy() - { - return null; //TODO - } - - public LifetimePolicy setLifetimePolicy(final LifetimePolicy expected, final LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return null; //TODO - } - - public long getTimeToLive() - { - return 0; //TODO - } - - public long setTimeToLive(final long expected, final long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return 0; //TODO - } - - @Override - public Collection<String> getAttributeNames() - { - return Consumer.AVAILABLE_ATTRIBUTES; - } - - @Override - public Object getAttribute(final String name) - { - if(ID.equals(name)) - { - return getId(); - } - else if(NAME.equals(name)) - { - return getName(); - } - else if(STATE.equals(name)) - { - - } - else if(DURABLE.equals(name)) - { - return false; - } - else if(LIFETIME_POLICY.equals(name)) - { - return LifetimePolicy.AUTO_DELETE; - } - else if(TIME_TO_LIVE.equals(name)) - { - - } - else if(CREATED.equals(name)) - { - - } - else if(UPDATED.equals(name)) - { - - } - else if(DISTRIBUTION_MODE.equals(name)) - { - return _subscription.acquires() ? "MOVE" : "COPY"; - } - else if(SETTLEMENT_MODE.equals(name)) - { - - } - else if(EXCLUSIVE.equals(name)) - { - - } - else if(NO_LOCAL.equals(name)) - { - - } - else if(SELECTOR.equals(name)) - { - - } - return super.getAttribute(name); //TODO - } - - public Statistics getStatistics() - { - return _statistics; - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - return Collections.emptySet(); - } - - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - throw new IllegalArgumentException(); - } - - private class ConsumerStatistics implements Statistics - { - - public Collection<String> getStatisticNames() - { - return AVAILABLE_STATISTICS; - } - - public Object getStatistic(String name) - { - if(name.equals(BYTES_OUT)) - { - return _subscription.getBytesOut(); - } - else if(name.equals(MESSAGES_OUT)) - { - return _subscription.getMessagesOut(); - } - else if(name.equals(STATE_CHANGED)) - { - - } - else if(name.equals(UNACKNOWLEDGED_BYTES)) - { - return _subscription.getUnacknowledgedBytes(); - } - else if(name.equals(UNACKNOWLEDGED_MESSAGES)) - { - return _subscription.getUnacknowledgedMessages(); - } - return null; // TODO - Implement - } - } - - @Override - protected boolean setState(State currentState, State desiredState) - { - // TODO : Add state management - return false; - } - - @Override - public Object setAttribute(final String name, final Object expected, final Object desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on consumer is not supported."); - } - - @Override - public void setAttributes(final Map<String, Object> attributes) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on consumer is not supported."); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java deleted file mode 100644 index 8efce39ea2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java +++ /dev/null @@ -1,444 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQInternalException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Exchange; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Publisher; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.util.MapValueConverter; -import org.apache.qpid.server.virtualhost.RequiredExchangeException; -import org.apache.qpid.server.virtualhost.VirtualHost; - -final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apache.qpid.server.exchange.Exchange.BindingListener -{ - - private final org.apache.qpid.server.exchange.Exchange _exchange; - private final Map<Binding, BindingAdapter> _bindingAdapters = - new HashMap<Binding, BindingAdapter>(); - private VirtualHostAdapter _vhost; - private final ExchangeStatistics _statistics; - - public ExchangeAdapter(final VirtualHostAdapter virtualHostAdapter, - final org.apache.qpid.server.exchange.Exchange exchange) - { - super(exchange.getId(), virtualHostAdapter.getTaskExecutor()); - _statistics = new ExchangeStatistics(); - _vhost = virtualHostAdapter; - _exchange = exchange; - addParent(org.apache.qpid.server.model.VirtualHost.class, virtualHostAdapter); - - exchange.addBindingListener(this); - populateBindings(); - } - - private void populateBindings() - { - Collection<Binding> actualBindings = _exchange.getBindings(); - synchronized (_bindingAdapters) - { - for(Binding binding : actualBindings) - { - if(!_bindingAdapters.containsKey(binding)) - { - QueueAdapter queueAdapter = _vhost.getQueueAdapter(binding.getQueue()); - BindingAdapter adapter = new BindingAdapter(binding, this, queueAdapter); - _bindingAdapters.put(binding, adapter); - - queueAdapter.bindingRegistered(binding, adapter); - } - } - } - - } - - public String getExchangeType() - { - return _exchange.getType().getType(); - } - - public Collection<org.apache.qpid.server.model.Binding> getBindings() - { - synchronized (_bindingAdapters) - { - return new ArrayList<org.apache.qpid.server.model.Binding>(_bindingAdapters.values()); - } - - } - - public Collection<Publisher> getPublishers() - { - // TODO - return Collections.emptyList(); - } - - - public org.apache.qpid.server.model.Binding createBinding(Queue queue, - Map<String, Object> attributes) - throws AccessControlException, IllegalStateException - { - attributes = new HashMap<String, Object>(attributes); - String bindingKey = MapValueConverter.getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, ""); - Map<String, Object> bindingArgs = MapValueConverter.getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.<String,Object>emptyMap()); - - attributes.remove(org.apache.qpid.server.model.Binding.NAME); - attributes.remove(org.apache.qpid.server.model.Binding.ARGUMENTS); - - return createBinding(bindingKey, queue, bindingArgs, attributes); - - } - - public org.apache.qpid.server.model.Binding createBinding(String bindingKey, Queue queue, - Map<String, Object> bindingArguments, - Map<String, Object> attributes) - throws AccessControlException, IllegalStateException - { - VirtualHost virtualHost = _vhost.getVirtualHost(); - - - AMQQueue amqQueue = ((QueueAdapter)queue).getAMQQueue(); - - try - { - if(!_exchange.addBinding(bindingKey, amqQueue, bindingArguments)) - { - Binding oldBinding = _exchange.getBinding(bindingKey, amqQueue, bindingArguments); - - Map<String, Object> oldArgs = oldBinding.getArguments(); - if((oldArgs == null && !bindingArguments.isEmpty()) || (oldArgs != null && !oldArgs.equals(bindingArguments))) - { - _exchange.replaceBinding(oldBinding.getId(), bindingKey, amqQueue, bindingArguments); - } - } - Binding binding = _exchange.getBinding(bindingKey, amqQueue, bindingArguments); - - synchronized (_bindingAdapters) - { - return binding == null ? null : _bindingAdapters.get(binding); - } - } - catch(AMQSecurityException e) - { - throw new AccessControlException(e.toString()); - } - catch(AMQInternalException e) - { - throw new IllegalStateException(e); - } - } - - public void delete() - { - try - { - _vhost.getVirtualHost().removeExchange(_exchange, true); - } - catch(RequiredExchangeException e) - { - throw new UnsupportedOperationException("'" + getName() + "' is a reserved exchange and can't be deleted"); - } - catch(AMQException e) - { - throw new IllegalStateException(e); - } - } - - public String getName() - { - return _exchange.getName(); - } - - public String setName(final String currentName, final String desiredName) - throws IllegalStateException, AccessControlException - { - return null; //TODO - } - - public State getActualState() - { - return null; //TODO - } - - public boolean isDurable() - { - return _exchange.isDurable(); - } - - public void setDurable(final boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - //TODO - } - - public LifetimePolicy getLifetimePolicy() - { - return _exchange.isAutoDelete() ? LifetimePolicy.AUTO_DELETE : LifetimePolicy.PERMANENT; - } - - public LifetimePolicy setLifetimePolicy(final LifetimePolicy expected, final LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return null; //TODO - } - - public long getTimeToLive() - { - return 0; //TODO - } - - public long setTimeToLive(final long expected, final long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return 0; //TODO - } - - public Statistics getStatistics() - { - return _statistics; - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if(clazz == org.apache.qpid.server.model.Binding.class) - { - return (Collection<C>) getBindings(); - } - else - { - return Collections.emptySet(); - } - } - - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - if(childClass == org.apache.qpid.server.model.Binding.class) - { - if(otherParents != null && otherParents.length == 1 && otherParents[0] instanceof Queue) - { - Queue queue = (Queue) otherParents[0]; - if(queue.getParent(org.apache.qpid.server.model.VirtualHost.class) == getParent(org.apache.qpid.server.model.VirtualHost.class)) - { - return (C) createBinding(queue, attributes); - } - else - { - throw new IllegalArgumentException("Queue and Exchange parents of a binding must be on same virtual host"); - } - } - else - { - throw new IllegalArgumentException("Other parent must be a queue"); - } - } - else - { - throw new IllegalArgumentException(); - } - } - - public void bindingAdded(org.apache.qpid.server.exchange.Exchange exchange, Binding binding) - { - BindingAdapter adapter = null; - synchronized (_bindingAdapters) - { - if(!_bindingAdapters.containsKey(binding)) - { - QueueAdapter queueAdapter = _vhost.getQueueAdapter(binding.getQueue()); - adapter = new BindingAdapter(binding, this, queueAdapter); - _bindingAdapters.put(binding,adapter); - queueAdapter.bindingRegistered(binding,adapter); - } - } - if(adapter != null) - { - childAdded(adapter); - } - } - - public void bindingRemoved(org.apache.qpid.server.exchange.Exchange exchange, Binding binding) - { - BindingAdapter adapter = null; - synchronized (_bindingAdapters) - { - adapter = _bindingAdapters.remove(binding); - } - if(adapter != null) - { - QueueAdapter queueAdapter = _vhost.getQueueAdapter(binding.getQueue()); - if(queueAdapter != null) - { - queueAdapter.bindingUnregistered(binding); - childRemoved(adapter); - } - } - } - - org.apache.qpid.server.exchange.Exchange getExchange() - { - return _exchange; - } - - @Override - public Object getAttribute(String name) - { - if(ID.equals(name)) - { - return getId(); - } - else if(NAME.equals(name)) - { - return getName(); - } - else if(STATE.equals(name)) - { - return State.ACTIVE; - } - else if(DURABLE.equals(name)) - { - return isDurable(); - } - else if(LIFETIME_POLICY.equals(name)) - { - return _exchange.isAutoDelete() ? LifetimePolicy.AUTO_DELETE : LifetimePolicy.PERMANENT; - } - else if(TIME_TO_LIVE.equals(name)) - { - - } - else if(CREATED.equals(name)) - { - - } - else if(UPDATED.equals(name)) - { - - } - else if(ALTERNATE_EXCHANGE.equals(name)) - { - return _exchange.getAlternateExchange(); - } - else if(TYPE.equals(name)) - { - return _exchange.getTypeName(); - } - return super.getAttribute(name); - } - - @Override - public Collection<String> getAttributeNames() - { - return AVAILABLE_ATTRIBUTES; - } - - @Override - protected boolean setState(State currentState, State desiredState) - { - if (desiredState == State.DELETED) - { - delete(); - return true; - } - return false; - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - throw new UnsupportedOperationException("Changing attributes on exchange is not supported."); - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_vhost.getSecurityManager().authoriseUpdate(_exchange)) - { - throw new AccessControlException("Setting of exchange attribute is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_vhost.getSecurityManager().authoriseUpdate(_exchange)) - { - throw new AccessControlException("Setting of exchange attributes is denied"); - } - } - - private class ExchangeStatistics implements Statistics - { - - public Collection<String> getStatisticNames() - { - return AVAILABLE_STATISTICS; - } - - public Object getStatistic(String name) - { - if(BINDING_COUNT.equals(name)) - { - return _exchange.getBindingCount(); - } - else if(BYTES_DROPPED.equals(name)) - { - return _exchange.getByteDrops(); - } - else if(BYTES_IN.equals(name)) - { - return _exchange.getByteReceives(); - } - else if(MESSAGES_DROPPED.equals(name)) - { - return _exchange.getMsgDrops(); - } - else if(MESSAGES_IN.equals(name)) - { - return _exchange.getMsgReceives(); - } - else if(PRODUCER_COUNT.equals(name)) - { - - } - else if(STATE_CHANGED.equals(name)) - { - - } - return null; // TODO - Implement - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProvider.java deleted file mode 100644 index f7560a0dfa..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProvider.java +++ /dev/null @@ -1,592 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.lang.reflect.Type; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.channels.OverlappingFileLockException; -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.log4j.Logger; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.util.MapValueConverter; -import org.codehaus.jackson.JsonParser; -import org.codehaus.jackson.JsonProcessingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; -import org.codehaus.jackson.type.TypeReference; - -public class FileSystemPreferencesProvider extends AbstractAdapter implements PreferencesProvider -{ - private static final Logger LOGGER = Logger.getLogger(FileSystemPreferencesProvider.class); - public static String PATH = "path"; - public static final String PROVIDER_TYPE = "FileSystemPreferences"; - - // TODO: use resolver to resolve path from - // '${qpid.work_dir}/preferences/${authenticationProviderName}' - @SuppressWarnings("serial") - private static final Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>() - {{ - put(PATH, System.getProperty("user.home") + File.separator + ".qpid" + File.separator + "preferences.json"); - put(TYPE, FileSystemPreferencesProvider.class.getSimpleName()); - }}); - - @SuppressWarnings("serial") - private static final Map<String, Type> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Type>() - {{ - put(NAME, String.class); - put(PATH, String.class); - put(TYPE, String.class); - }}); - - @SuppressWarnings("serial") - private static Collection<String> AVAILABLE_ATTRIBUTES = Collections.unmodifiableList(new ArrayList<String>( - PreferencesProvider.AVAILABLE_ATTRIBUTES) - {{ - add(PATH); - }}); - - private final AuthenticationProvider _authenticationProvider; - private AtomicReference<State> _state; - - private final ObjectMapper _objectMapper; - private final Map<String, Map<String, Object>> _preferences; - private File _preferencesLocation; - private FileLock _fileLock; - - protected FileSystemPreferencesProvider(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProvider, TaskExecutor taskExecutor) - { - super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor); - State state = MapValueConverter.getEnumAttribute(State.class, STATE, attributes, State.INITIALISING); - _state = new AtomicReference<State>(state); - addParent(AuthenticationProvider.class, authenticationProvider); - _authenticationProvider = authenticationProvider; - _objectMapper = new ObjectMapper(); - _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); - _objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - _preferences = new TreeMap<String, Map<String, Object>>(); - _preferencesLocation = new File(MapValueConverter.getStringAttribute(PATH, attributes)); - _preferences.putAll(load(_objectMapper, _preferencesLocation)); - } - - @Override - public Collection<String> getAttributeNames() - { - return AVAILABLE_ATTRIBUTES; - } - - @Override - public String getName() - { - return (String) getAttribute(AuthenticationProvider.NAME); - } - - @Override - public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException - { - throw new UnsupportedOperationException(); - } - - @Override - public State getActualState() - { - return _state.get(); - } - - @Override - public boolean isDurable() - { - return true; - } - - @Override - public void setDurable(boolean durable) throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException(); - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException(); - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new UnsupportedOperationException(); - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - return Collections.emptySet(); - } - - @Override - public Object getAttribute(String name) - { - if (CREATED.equals(name)) - { - // TODO - } - else if (DURABLE.equals(name)) - { - return true; - } - else if (ID.equals(name)) - { - return getId(); - } - else if (LIFETIME_POLICY.equals(name)) - { - return LifetimePolicy.PERMANENT; - } - else if (STATE.equals(name)) - { - return getActualState(); - } - else if (TIME_TO_LIVE.equals(name)) - { - // TODO - } - else if (UPDATED.equals(name)) - { - // TODO - } - return super.getAttribute(name); - } - - @Override - public boolean setState(State currentState, State desiredState) throws IllegalStateTransitionException, - AccessControlException - { - State state = _state.get(); - if (desiredState == State.DELETED) - { - if ((state == State.INITIALISING || state == State.ACTIVE || state == State.STOPPED || state == State.QUIESCED || state == State.ERRORED) - && _state.compareAndSet(state, State.DELETED)) - { - try - { - close(); - } - finally - { - _preferencesLocation.delete(); - _authenticationProvider.setPreferencesProvider(null); - } - return true; - } - else - { - throw new IllegalStateException("Cannot delete preferences provider in state: " + state); - } - } - else if (desiredState == State.ACTIVE) - { - if ((state == State.INITIALISING || state == State.QUIESCED || state == State.STOPPED) - && _state.compareAndSet(state, State.ACTIVE)) - { - try - { - getFileLock(); - Map<String, Map<String, Object>> preferences = load(_objectMapper, _preferencesLocation); - setPreferences(preferences); - return true; - } - catch (Exception e) - { - _state.compareAndSet(State.ACTIVE, State.ERRORED); - Broker broker = getAuthenticationProvider().getParent(Broker.class); - if (broker != null && broker.isManagementMode()) - { - LOGGER.warn("Failed to activate preferences provider: " + getName(), e); - } - else - { - throw new RuntimeException(e); - } - } - } - else - { - throw new IllegalStateException("Cannot activate preferences provider in state: " + state); - } - } - else if (desiredState == State.QUIESCED) - { - if (state == State.INITIALISING && _state.compareAndSet(state, State.QUIESCED)) - { - close(); - return true; - } - } - else if (desiredState == State.STOPPED) - { - if (_state.compareAndSet(state, State.STOPPED)) - { - close(); - return true; - } - else - { - throw new IllegalStateException("Cannot stop authentication preferences in state: " + state); - } - } - - return false; - } - - @Override - public Map<String, Object> getPreferences(String userId) - { - Map<String, Object> userPreferences = null; - synchronized (_preferences) - { - userPreferences = _preferences.get(userId); - } - if (userPreferences != null) - { - return new HashMap<String, Object>(userPreferences); - } - return Collections.emptyMap(); - } - - @Override - public Map<String, Object> setPreferences(String userId, Map<String, Object> preferences) - { - Map<String, Object> userPreferences = null; - synchronized (_preferences) - { - userPreferences = _preferences.get(userId); - if (userPreferences == null) - { - userPreferences = new HashMap<String, Object>(preferences); - _preferences.put(userId, userPreferences); - } - else - { - userPreferences.putAll(preferences); - } - savePreferences(); - } - return userPreferences; - } - - @Override - public Map<String, Object> deletePreferences(String userId) - { - Map<String, Object> userPreferences = null; - synchronized (_preferences) - { - if (_preferences.containsKey(userId)) - { - userPreferences = _preferences.remove(userId); - savePreferences(); - } - } - return userPreferences; - } - - @Override - public Set<String> listUserIDs() - { - synchronized (_preferences) - { - return Collections.unmodifiableSet(_preferences.keySet()); - } - } - - public AuthenticationProvider getAuthenticationProvider() - { - return _authenticationProvider; - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - Map<String, Object> effectiveAttributes = MapValueConverter.convert(super.generateEffectiveAttributes(attributes), - ATTRIBUTE_TYPES); - validateAttributes(effectiveAttributes); - String effectivePath = (String) effectiveAttributes.get(PATH); - String currentPath = (String) getAttribute(PATH); - Map<String, Map<String, Object>> newPreferences = null; - File storeFile = new File(effectivePath); - if (!effectivePath.equals(currentPath)) - { - if (!storeFile.exists()) - { - throw new IllegalConfigurationException("Path to preferences file does not exist!"); - } - newPreferences = load(_objectMapper, storeFile); - } - super.changeAttributes(attributes); - - if (newPreferences != null) - { - setPreferences(newPreferences); - _preferencesLocation = storeFile; - } - - // if provider was previously in ERRORED state then set its state to - // ACTIVE - _state.compareAndSet(State.ERRORED, State.ACTIVE); - } - - private void setPreferences(Map<String, Map<String, Object>> preferences) - { - synchronized (_preferences) - { - _preferences.clear(); - _preferences.putAll(preferences); - } - } - - private void validateAttributes(Map<String, Object> attributes) - { - super.validateChangeAttributes(attributes); - - String newName = (String) attributes.get(NAME); - String currentName = getName(); - if (!currentName.equals(newName)) - { - throw new IllegalConfigurationException("Changing the name of preferences provider is not supported"); - } - String newType = (String) attributes.get(TYPE); - String currentType = (String) getAttribute(TYPE); - if (!currentType.equals(newType)) - { - throw new IllegalConfigurationException("Changing the type of preferences provider is not supported"); - } - String path = (String) attributes.get(PATH); - if (path == null || path.equals("") || !(path instanceof String)) - { - throw new IllegalConfigurationException("Path to preferences file is not specified"); - } - } - - public File createStoreIfNotExist() - { - String path = (String)getAttribute(PATH); - File preferencesLocation = new File(path); - if (!preferencesLocation.exists()) - { - File parent = preferencesLocation.getParentFile(); - if (!parent.exists() && !parent.mkdirs()) - { - throw new IllegalConfigurationException("Cannot store preferences at " + path); - } - try - { - preferencesLocation.createNewFile(); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot store preferences at " + path); - } - } - return preferencesLocation; - } - - private Map<String, Map<String, Object>> load(ObjectMapper mapper, File file) - { - if (!file.exists() || file.length() == 0) - { - return Collections.emptyMap(); - } - - try - { - return mapper.readValue(file, new TypeReference<Map<String, Map<String, Object>>>() - { - }); - } - catch (JsonProcessingException e) - { - throw new IllegalConfigurationException("Cannot parse json", e); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot read json", e); - } - } - - private void savePreferences() - { - save(_objectMapper, _preferencesLocation, _preferences); - } - - private void save(ObjectMapper mapper, File file, Map<String, Map<String, Object>> preferences) - { - try - { - RandomAccessFile raf = new RandomAccessFile(file, "rw"); - try - { - FileChannel channel = raf.getChannel(); - try - { - FileLock lock = null; - try - { - lock = channel.tryLock(); - if (lock == null) - { - throw new IllegalConfigurationException("Cannot aquire exclusive lock on preferences file for " - + getName()); - } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - mapper.writeValue(baos, preferences); - channel.write(ByteBuffer.wrap(baos.toByteArray())); - } - catch (OverlappingFileLockException e) - { - throw new IllegalConfigurationException("Cannot aquire exclusive lock on preferences file for " - + getName(), e); - } - finally - { - if (lock != null) - { - lock.release(); - } - } - } - finally - { - channel.close(); - } - } - finally - { - raf.close(); - } - } - catch (FileNotFoundException e) - { - throw new IllegalConfigurationException("Cannot find preferences file for " + getName(), e); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot store preferences file for " + getName(), e); - } - } - - private void getFileLock() throws IOException, AMQStoreException - { - File lockFile = new File(getLockFileName()); - lockFile.createNewFile(); - - FileOutputStream out = new FileOutputStream(lockFile); - FileChannel channel = out.getChannel(); - try - { - _fileLock = channel.tryLock(); - } - catch(OverlappingFileLockException e) - { - _fileLock = null; - } - if(_fileLock == null) - { - throw new AMQStoreException("Cannot get lock on file " + lockFile.getAbsolutePath() + " is another instance running?"); - } - lockFile.deleteOnExit(); - } - - private String getLockFileName() - { - return _preferencesLocation.getAbsolutePath() + ".lck"; - } - - public void close() - { - try - { - releaseFileLock(); - } - catch(IOException e) - { - LOGGER.error("Cannot close file system preferences provider", e); - } - finally - { - new File(getLockFileName()).delete(); - _fileLock = null; - _preferences.clear(); - } - } - - private void releaseFileLock() throws IOException - { - _fileLock.release(); - _fileLock.channel().close(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderFactory.java deleted file mode 100644 index 32ee910973..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderFactory.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.plugin.PreferencesProviderFactory; - -public class FileSystemPreferencesProviderFactory implements PreferencesProviderFactory -{ - - @Override - public String getType() - { - return FileSystemPreferencesProvider.PROVIDER_TYPE; - } - - @Override - public PreferencesProvider createInstance(UUID id, Map<String, Object> attributes, - AuthenticationProvider authenticationProvider) - { - Broker broker = authenticationProvider.getParent(Broker.class); - FileSystemPreferencesProvider provider = new FileSystemPreferencesProvider(id, attributes, authenticationProvider, broker.getTaskExecutor()); - - // create store if such does not exist - provider.createStoreIfNotExist(); - return provider; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java deleted file mode 100644 index 9323606c83..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java +++ /dev/null @@ -1,710 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.security.Principal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Group; -import org.apache.qpid.server.model.GroupMember; -import org.apache.qpid.server.model.GroupProvider; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.security.group.GroupManager; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.util.MapValueConverter; - -public class GroupProviderAdapter extends AbstractAdapter implements - GroupProvider -{ - private static Logger LOGGER = Logger.getLogger(GroupProviderAdapter.class); - - private final GroupManager _groupManager; - private final Broker _broker; - private Collection<String> _supportedAttributes; - private AtomicReference<State> _state; - - public GroupProviderAdapter(UUID id, Broker broker, GroupManager groupManager, Map<String, Object> attributes, Collection<String> attributeNames) - { - super(id, null, null, broker.getTaskExecutor()); - - if (groupManager == null) - { - throw new IllegalArgumentException("GroupManager must not be null"); - } - _groupManager = groupManager; - _broker = broker; - _supportedAttributes = createSupportedAttributes(attributeNames); - State state = MapValueConverter.getEnumAttribute(State.class, STATE, attributes, State.INITIALISING); - _state = new AtomicReference<State>(state); - addParent(Broker.class, broker); - - // set attributes now after all attribute names are known - if (attributes != null) - { - for (String name : _supportedAttributes) - { - if (attributes.containsKey(name)) - { - changeAttribute(name, null, attributes.get(name)); - } - } - } - } - - protected Collection<String> createSupportedAttributes(Collection<String> factoryAttributes) - { - List<String> attributesNames = new ArrayList<String>(AVAILABLE_ATTRIBUTES); - if (factoryAttributes != null) - { - attributesNames.addAll(factoryAttributes); - } - - return Collections.unmodifiableCollection(attributesNames); - } - - @Override - public String getName() - { - return (String)getAttribute(NAME); - } - - @Override - public String setName(String currentName, String desiredName) - throws IllegalStateException, AccessControlException - { - return null; - } - - @Override - public State getActualState() - { - return _state.get(); - } - - @Override - public boolean isDurable() - { - return true; - } - - @Override - public void setDurable(boolean durable) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, - LifetimePolicy desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - return null; - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) - throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - return 0; - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public Collection<String> getAttributeNames() - { - return _supportedAttributes; - } - - @Override - public Object getAttribute(String name) - { - if (CREATED.equals(name)) - { - // TODO - } - else if (DURABLE.equals(name)) - { - return true; - } - else if (ID.equals(name)) - { - return getId(); - } - else if (LIFETIME_POLICY.equals(name)) - { - return LifetimePolicy.PERMANENT; - } - else if (STATE.equals(name)) - { - return getActualState(); - } - else if (TIME_TO_LIVE.equals(name)) - { - // TODO - } - else if (UPDATED.equals(name)) - { - // TODO - } - return super.getAttribute(name); - } - - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, - Map<String, Object> attributes, ConfiguredObject... otherParents) - { - if (childClass == Group.class) - { - String groupName = (String) attributes.get(Group.NAME); - - if (getSecurityManager().authoriseGroupOperation(Operation.CREATE, groupName)) - { - _groupManager.createGroup(groupName); - return (C) new GroupAdapter(groupName, getTaskExecutor()); - } - else - { - throw new AccessControlException("Do not have permission" + - " to create new group"); - } - } - - throw new IllegalArgumentException( - "This group provider does not support creating children of type: " - + childClass); - } - - @SuppressWarnings("unchecked") - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if (clazz == Group.class) - { - Set<Principal> groups = _groupManager.getGroupPrincipals(); - Collection<Group> principals = new ArrayList<Group>(groups.size()); - for (Principal group : groups) - { - principals.add(new GroupAdapter(group.getName(), getTaskExecutor())); - } - return (Collection<C>) Collections - .unmodifiableCollection(principals); - } - else - { - return null; - } - } - - public GroupManager getGroupManager() - { - return _groupManager; - } - - private SecurityManager getSecurityManager() - { - return _broker.getSecurityManager(); - } - - @Override - protected boolean setState(State currentState, State desiredState) - { - State state = _state.get(); - if (desiredState == State.ACTIVE) - { - if ((state == State.INITIALISING || state == State.QUIESCED || state == State.STOPPED) - && _state.compareAndSet(state, State.ACTIVE)) - { - try - { - _groupManager.open(); - return true; - } - catch(RuntimeException e) - { - _state.compareAndSet(State.ACTIVE, State.ERRORED); - if (_broker.isManagementMode()) - { - LOGGER.warn("Failed to activate group provider: " + getName(), e); - } - else - { - throw e; - } - } - } - else - { - throw new IllegalStateException("Cannot activate group provider in state: " + state); - } - } - else if (desiredState == State.STOPPED) - { - if (_state.compareAndSet(state, State.STOPPED)) - { - _groupManager.close(); - return true; - } - else - { - throw new IllegalStateException("Cannot stop group provider in state: " + state); - } - } - else if (desiredState == State.DELETED) - { - if ((state == State.INITIALISING || state == State.ACTIVE || state == State.STOPPED || state == State.QUIESCED || state == State.ERRORED) - && _state.compareAndSet(state, State.DELETED)) - { - _groupManager.close(); - _groupManager.onDelete(); - return true; - } - else - { - throw new IllegalStateException("Cannot delete group provider in state: " + state); - } - } - else if (desiredState == State.QUIESCED) - { - if (state == State.INITIALISING && _state.compareAndSet(state, State.QUIESCED)) - { - return true; - } - } - return false; - } - - public Set<Principal> getGroupPrincipalsForUser(String username) - { - return _groupManager.getGroupPrincipalsForUser(username); - } - - @Override - protected void childAdded(ConfiguredObject child) - { - // no-op, prevent storing groups in the broker store - } - - @Override - protected void childRemoved(ConfiguredObject child) - { - // no-op, as per above, groups are not in the store - } - - @Override - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - if(desiredState == State.DELETED) - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), GroupProvider.class, Operation.DELETE)) - { - throw new AccessControlException("Deletion of groups provider is denied"); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), GroupProvider.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of group provider attributes is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), GroupProvider.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of group provider attributes is denied"); - } - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - throw new UnsupportedOperationException("Changing attributes on group providers is not supported."); - } - - private class GroupAdapter extends AbstractAdapter implements Group - { - private final String _group; - - public GroupAdapter(String group, TaskExecutor taskExecutor) - { - super(UUIDGenerator.generateGroupUUID(GroupProviderAdapter.this.getName(), group), taskExecutor); - _group = group; - - } - - @Override - public String getName() - { - return _group; - } - - @Override - public String setName(String currentName, String desiredName) - throws IllegalStateException, AccessControlException - { - throw new IllegalStateException("Names cannot be updated"); - } - - @Override - public State getActualState() - { - return State.ACTIVE; - } - - @Override - public boolean isDurable() - { - return true; - } - - @Override - public void setDurable(boolean durable) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new IllegalStateException("Durability cannot be updated"); - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, - LifetimePolicy desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new IllegalStateException("LifetimePolicy cannot be updated"); - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) - throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new IllegalStateException("ttl cannot be updated"); - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren( - Class<C> clazz) - { - if (clazz == GroupMember.class) - { - Set<Principal> usersInGroup = _groupManager - .getUserPrincipalsForGroup(_group); - Collection<GroupMember> members = new ArrayList<GroupMember>(); - for (Principal principal : usersInGroup) - { - members.add(new GroupMemberAdapter(principal.getName(), getTaskExecutor())); - } - return (Collection<C>) Collections - .unmodifiableCollection(members); - } - else - { - return null; - } - - } - - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, - Map<String, Object> attributes, - ConfiguredObject... otherParents) - { - if (childClass == GroupMember.class) - { - String memberName = (String) attributes.get(GroupMember.NAME); - - if (getSecurityManager().authoriseGroupOperation(Operation.UPDATE, _group)) - { - _groupManager.addUserToGroup(memberName, _group); - return (C) new GroupMemberAdapter(memberName, getTaskExecutor()); - } - else - { - throw new AccessControlException("Do not have permission" + - " to add new group member"); - } - } - - throw new IllegalArgumentException( - "This group provider does not support creating children of type: " - + childClass); - } - - @Override - public Collection<String> getAttributeNames() - { - return Group.AVAILABLE_ATTRIBUTES; - } - - @Override - public Object getAttribute(String name) - { - if (ID.equals(name)) - { - return getId(); - } - else if (NAME.equals(name)) - { - return getName(); - } - return super.getAttribute(name); - } - - @Override - protected boolean setState(State currentState, State desiredState) - throws IllegalStateTransitionException, AccessControlException - { - if (desiredState == State.DELETED) - { - if (getSecurityManager().authoriseGroupOperation(Operation.DELETE, _group)) - { - _groupManager.removeGroup(_group); - return true; - } - else - { - throw new AccessControlException("Do not have permission to delete group"); - } - } - - return false; - } - - @Override - public Object setAttribute(final String name, final Object expected, final Object desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on group is not supported."); - } - - @Override - public void setAttributes(final Map<String, Object> attributes) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on group is not supported."); - } - - private class GroupMemberAdapter extends AbstractAdapter implements - GroupMember - { - private String _memberName; - - public GroupMemberAdapter(String memberName, TaskExecutor taskExecutor) - { - super(UUIDGenerator.generateGroupMemberUUID(GroupProviderAdapter.this.getName(), _group, memberName), taskExecutor); - _memberName = memberName; - } - - @Override - public Collection<String> getAttributeNames() - { - return GroupMember.AVAILABLE_ATTRIBUTES; - } - - @Override - public Object getAttribute(String name) - { - if (ID.equals(name)) - { - return getId(); - } - else if (NAME.equals(name)) - { - return getName(); - } - return super.getAttribute(name); - } - - @Override - public String getName() - { - return _memberName; - } - - @Override - public String setName(String currentName, String desiredName) - throws IllegalStateException, AccessControlException - { - return null; - } - - @Override - public State getActualState() - { - return null; - } - - @Override - public boolean isDurable() - { - return false; - } - - @Override - public void setDurable(boolean durable) - throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return null; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, - LifetimePolicy desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - return null; - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) - throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - return 0; - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren( - Class<C> clazz) - { - return null; - } - - @Override - public <C extends ConfiguredObject> C createChild( - Class<C> childClass, Map<String, Object> attributes, - ConfiguredObject... otherParents) - { - return null; - } - - @Override - protected boolean setState(State currentState, State desiredState) - throws IllegalStateTransitionException, - AccessControlException - { - if (desiredState == State.DELETED) - { - if (getSecurityManager().authoriseGroupOperation(Operation.UPDATE, _group)) - { - _groupManager.removeUserFromGroup(_memberName, _group); - return true; - } - else - { - throw new AccessControlException("Do not have permission to remove group member"); - } - } - return false; - } - - @Override - public Object setAttribute(final String name, final Object expected, final Object desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on group member is not supported."); - } - - @Override - public void setAttributes(final Map<String, Object> attributes) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on group member is not supported."); - } - } - } - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderFactory.java deleted file mode 100644 index 1d3ccd81b3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderFactory.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.GroupProvider; -import org.apache.qpid.server.plugin.GroupManagerFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; -import org.apache.qpid.server.security.group.GroupManager; - -public class GroupProviderFactory -{ - private final Map<String, GroupManagerFactory> _factories; - private Collection<String> _supportedGroupProviders; - - public GroupProviderFactory(QpidServiceLoader<GroupManagerFactory> groupManagerFactoryServiceLoader) - { - Iterable<GroupManagerFactory> factories = groupManagerFactoryServiceLoader.instancesOf(GroupManagerFactory.class); - - Map<String, GroupManagerFactory> registeredGroupProviderFactories = new HashMap<String, GroupManagerFactory>(); - for (GroupManagerFactory factory : factories) - { - GroupManagerFactory existingFactory = registeredGroupProviderFactories.put(factory.getType(), factory); - if (existingFactory != null) - { - throw new IllegalConfigurationException("Group provider factory of the same type '" + factory.getType() - + "' is already registered using class '" + existingFactory.getClass().getName() - + "', can not register class '" + factory.getClass().getName() + "'"); - } - } - _factories = registeredGroupProviderFactories; - _supportedGroupProviders = Collections.unmodifiableCollection(registeredGroupProviderFactories.keySet()); - } - - /** - * Creates {@link GroupProvider} for given ID, {@link Broker} and attributes. - * <p> - * The configured {@link GroupManagerFactory}'s are used to try to create the {@link GroupProvider}. The first non-null - * instance is returned. The factories are used in non-deterministic order. - */ - public GroupProvider create(UUID id, Broker broker, Map<String, Object> attributes) - { - GroupProviderAdapter authenticationProvider = createGroupProvider(id, broker, attributes); - authenticationProvider.getGroupManager().onCreate(); - return authenticationProvider; - } - - /** - * Recovers {@link GroupProvider} with given ID, {@link Broker} and attributes. - * <p> - * The configured {@link GroupManagerFactory}'s are used to try to create the {@link GroupProvider}. The first non-null - * instance is returned. The factories are used in non-deterministic order. - */ - public GroupProvider recover(UUID id, Broker broker, Map<String, Object> attributes) - { - return createGroupProvider(id, broker, attributes); - } - - public Collection<String> getSupportedGroupProviders() - { - return _supportedGroupProviders; - } - - private GroupProviderAdapter createGroupProvider(UUID id, Broker broker, Map<String, Object> attributes) - { - for (GroupManagerFactory factory : _factories.values()) - { - GroupManager manager = factory.createInstance(attributes); - if (manager != null) - { - verifyGroupManager(manager, broker); - return new GroupProviderAdapter(id, broker, manager, attributes,factory.getAttributeNames()); - } - } - throw new IllegalConfigurationException("No group provider factory found for configuration attributes " + attributes); - } - - private void verifyGroupManager(GroupManager manager, Broker broker) - { - Collection<GroupProvider> groupProviders = broker.getGroupProviders(); - for (GroupProvider groupProvider : groupProviders) - { - if (groupProvider instanceof GroupProviderAdapter) - { - GroupManager providerManager = ((GroupProviderAdapter) groupProvider).getGroupManager(); - if (manager.equals(providerManager)) - { - throw new IllegalConfigurationException("A group provider with the same settings already exists"); - } - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java deleted file mode 100644 index 1101232c96..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.security.AccessControlException; -import java.security.GeneralSecurityException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.Certificate; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.IntegrityViolationException; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.util.MapValueConverter; -import org.apache.qpid.transport.network.security.ssl.QpidClientX509KeyManager; -import org.apache.qpid.transport.network.security.ssl.SSLUtil; - -public class KeyStoreAdapter extends AbstractKeyStoreAdapter implements KeyStore -{ - @SuppressWarnings("serial") - public static final Map<String, Type> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Type>(){{ - put(NAME, String.class); - put(PATH, String.class); - put(PASSWORD, String.class); - put(TYPE, String.class); - put(CERTIFICATE_ALIAS, String.class); - put(KEY_MANAGER_FACTORY_ALGORITHM, String.class); - }}); - - @SuppressWarnings("serial") - public static final Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>(){{ - put(KeyStore.TYPE, DEFAULT_KEYSTORE_TYPE); - put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, KeyManagerFactory.getDefaultAlgorithm()); - }}); - - private Broker _broker; - - public KeyStoreAdapter(UUID id, Broker broker, Map<String, Object> attributes) - { - super(id, broker, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES)); - _broker = broker; - - String keyStorePath = (String)getAttribute(KeyStore.PATH); - String keyStorePassword = getPassword(); - String keyStoreType = (String)getAttribute(KeyStore.TYPE); - String keyManagerFactoryAlgorithm = (String)getAttribute(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM); - String certAlias = (String)getAttribute(KeyStore.CERTIFICATE_ALIAS); - - validateKeyStoreAttributes(keyStoreType, keyStorePath, keyStorePassword, - certAlias, keyManagerFactoryAlgorithm); - } - - @Override - public Collection<String> getAttributeNames() - { - return AVAILABLE_ATTRIBUTES; - } - - @Override - protected boolean setState(State currentState, State desiredState) - { - if(desiredState == State.DELETED) - { - // verify that it is not in use - String storeName = getName(); - - Collection<Port> ports = new ArrayList<Port>(_broker.getPorts()); - for (Port port : ports) - { - if (storeName.equals(port.getAttribute(Port.KEY_STORE))) - { - throw new IntegrityViolationException("Key store '" + storeName + "' can't be deleted as it is in use by a port:" + port.getName()); - } - } - - return true; - } - - return false; - } - - @Override - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - if(desiredState == State.DELETED) - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), KeyStore.class, Operation.DELETE)) - { - throw new AccessControlException("Deletion of key store is denied"); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - authoriseSetAttribute(); - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - authoriseSetAttribute(); - } - - private void authoriseSetAttribute() - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), KeyStore.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting key store attributes is denied"); - } - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - Map<String, Object> changedValues = MapValueConverter.convert(attributes, ATTRIBUTE_TYPES); - if(changedValues.containsKey(KeyStore.NAME)) - { - String newName = (String) changedValues.get(KeyStore.NAME); - if(!getName().equals(newName)) - { - throw new IllegalConfigurationException("Changing the key store name is not allowed"); - } - } - - Map<String, Object> merged = generateEffectiveAttributes(changedValues); - - String keyStorePath = (String)merged.get(KeyStore.PATH); - String keyStorePassword = (String) merged.get(KeyStore.PASSWORD); - String keyStoreType = (String)merged.get(KeyStore.TYPE); - String keyManagerFactoryAlgorithm = (String)merged.get(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM); - String certAlias = (String)merged.get(KeyStore.CERTIFICATE_ALIAS); - - validateKeyStoreAttributes(keyStoreType, keyStorePath, keyStorePassword, - certAlias, keyManagerFactoryAlgorithm); - - super.changeAttributes(changedValues); - } - - private void validateKeyStoreAttributes(String type, String keyStorePath, - String keyStorePassword, String alias, - String keyManagerFactoryAlgorithm) - { - java.security.KeyStore keyStore = null; - try - { - keyStore = SSLUtil.getInitializedKeyStore(keyStorePath, keyStorePassword, type); - } - catch (Exception e) - { - throw new IllegalConfigurationException("Cannot instantiate key store at " + keyStorePath, e); - } - - if (alias != null) - { - Certificate cert = null; - try - { - cert = keyStore.getCertificate(alias); - } - catch (KeyStoreException e) - { - // key store should be initialized above - throw new RuntimeException("Key store has not been initialized", e); - } - if (cert == null) - { - throw new IllegalConfigurationException("Cannot find a certificate with alias " + alias - + "in key store : " + keyStorePath); - } - } - - try - { - KeyManagerFactory.getInstance(keyManagerFactoryAlgorithm); - } - catch (NoSuchAlgorithmException e) - { - throw new IllegalConfigurationException("Unknown keyManagerFactoryAlgorithm: " - + keyManagerFactoryAlgorithm); - } - } - - public KeyManager[] getKeyManagers() throws GeneralSecurityException - { - String keyStorePath = (String)getAttribute(KeyStore.PATH); - String keyStorePassword = getPassword(); - String keyStoreType = (String)getAttribute(KeyStore.TYPE); - String keyManagerFactoryAlgorithm = (String)getAttribute(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM); - String certAlias = (String)getAttribute(KeyStore.CERTIFICATE_ALIAS); - - try - { - if (certAlias != null) - { - return new KeyManager[] { - new QpidClientX509KeyManager( certAlias, keyStorePath, keyStoreType, keyStorePassword, - keyManagerFactoryAlgorithm) - }; - - } - else - { - final java.security.KeyStore ks = SSLUtil.getInitializedKeyStore(keyStorePath, keyStorePassword, keyStoreType); - - char[] keyStoreCharPassword = keyStorePassword == null ? null : keyStorePassword.toCharArray(); - - final KeyManagerFactory kmf = KeyManagerFactory.getInstance(keyManagerFactoryAlgorithm); - - kmf.init(ks, keyStoreCharPassword); - - return kmf.getKeyManagers(); - } - } - catch (IOException e) - { - throw new GeneralSecurityException(e); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/NoStatistics.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/NoStatistics.java deleted file mode 100644 index 03fdbd1e85..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/NoStatistics.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.qpid.server.model.adapter; - -import org.apache.qpid.server.model.Statistics; - -import java.util.Collection; -import java.util.Collections; - -public class NoStatistics implements Statistics -{ - private static final NoStatistics INSTANCE = new NoStatistics(); - - private NoStatistics() - { - } - - public Collection<String> getStatisticNames() - { - return Collections.emptyList(); - } - - public Object getStatistic(String name) - { - return null; - } - - public static NoStatistics getInstance() - { - return INSTANCE; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java deleted file mode 100644 index 0547f961d0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java +++ /dev/null @@ -1,559 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.lang.reflect.Type; -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Connection; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Protocol; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.model.VirtualHostAlias; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.util.MapValueConverter; -import org.apache.qpid.server.util.ParameterizedTypeImpl; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.updater.TaskExecutor; - -public class PortAdapter extends AbstractAdapter implements Port -{ - @SuppressWarnings("serial") - public static final Map<String, Type> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Type>(){{ - put(NAME, String.class); - put(PROTOCOLS, new ParameterizedTypeImpl(Set.class, Protocol.class)); - put(TRANSPORTS, new ParameterizedTypeImpl(Set.class, Transport.class)); - put(TRUST_STORES, new ParameterizedTypeImpl(Set.class, String.class)); - put(KEY_STORE, String.class); - put(PORT, Integer.class); - put(TCP_NO_DELAY, Boolean.class); - put(RECEIVE_BUFFER_SIZE, Integer.class); - put(SEND_BUFFER_SIZE, Integer.class); - put(NEED_CLIENT_AUTH, Boolean.class); - put(WANT_CLIENT_AUTH, Boolean.class); - put(BINDING_ADDRESS, String.class); - put(STATE, State.class); - put(AUTHENTICATION_PROVIDER, String.class); - }}); - - private final Broker _broker; - private AuthenticationProvider _authenticationProvider; - private AtomicReference<State> _state; - - public PortAdapter(UUID id, Broker broker, Map<String, Object> attributes, Map<String, Object> defaults, TaskExecutor taskExecutor) - { - super(id, defaults, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor); - _broker = broker; - State state = MapValueConverter.getEnumAttribute(State.class, STATE, attributes, State.INITIALISING); - - Collection<Protocol> protocols = getProtocols(); - boolean rmiRegistry = protocols != null && protocols.contains(Protocol.RMI); - if (!rmiRegistry) - { - String authProvider = (String)getAttribute(Port.AUTHENTICATION_PROVIDER); - if (authProvider == null) - { - throw new IllegalConfigurationException("An authentication provider must be specified for port : " + getName()); - } - _authenticationProvider = broker.findAuthenticationProviderByName(authProvider); - - if(_authenticationProvider == null) - { - throw new IllegalConfigurationException("The authentication provider '" + authProvider + "' could not be found for port : " + getName()); - } - } - - _state = new AtomicReference<State>(state); - addParent(Broker.class, broker); - } - - @Override - public String getBindingAddress() - { - return (String)getAttribute(BINDING_ADDRESS); - } - - @Override - public int getPort() - { - return (Integer)getAttribute(PORT); - } - - @SuppressWarnings("unchecked") - @Override - public Collection<Transport> getTransports() - { - return (Collection<Transport>)getAttribute(TRANSPORTS); - } - - @Override - public void addTransport(Transport transport) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public Transport removeTransport(Transport transport) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @SuppressWarnings("unchecked") - @Override - public Collection<Protocol> getProtocols() - { - return (Collection<Protocol>)getAttribute(PROTOCOLS); - } - - @Override - public void addProtocol(Protocol protocol) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public Protocol removeProtocol(Protocol protocol) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public Collection<VirtualHostAlias> getVirtualHostBindings() - { - List<VirtualHostAlias> aliases = new ArrayList<VirtualHostAlias>(); - for(VirtualHost vh : _broker.getVirtualHosts()) - { - for(VirtualHostAlias alias : vh.getAliases()) - { - if(alias.getPort().equals(this)) - { - aliases.add(alias); - } - } - } - return Collections.unmodifiableCollection(aliases); - } - - @Override - public Collection<Connection> getConnections() - { - return null; - } - - @Override - public String getName() - { - return (String)getAttribute(NAME); - } - - @Override - public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException - { - throw new IllegalStateException(); - } - - @Override - public State getActualState() - { - return _state.get(); - } - - @Override - public boolean isDurable() - { - return false; - } - - @Override - public void setDurable(boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public long getTimeToLive() - { - return 0; - } - - @Override - public long setTimeToLive(long expected, long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if(clazz == Connection.class) - { - return (Collection<C>) getConnections(); - } - else - { - return Collections.emptySet(); - } - } - - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - throw new UnsupportedOperationException(); - } - - @Override - public Object getAttribute(String name) - { - if(ID.equals(name)) - { - return getId(); - } - else if(STATE.equals(name)) - { - return getActualState(); - } - else if(DURABLE.equals(name)) - { - return isDurable(); - } - else if(LIFETIME_POLICY.equals(name)) - { - return getLifetimePolicy(); - } - else if(TIME_TO_LIVE.equals(name)) - { - return getTimeToLive(); - } - else if(CREATED.equals(name)) - { - - } - else if(UPDATED.equals(name)) - { - - } - return super.getAttribute(name); - } - - @Override - public Collection<String> getAttributeNames() - { - return AVAILABLE_ATTRIBUTES; - } - - @Override - public boolean setState(State currentState, State desiredState) - { - State state = _state.get(); - if (desiredState == State.DELETED) - { - if (state == State.INITIALISING || state == State.ACTIVE || state == State.STOPPED || state == State.QUIESCED || state == State.ERRORED) - { - return _state.compareAndSet(state, State.DELETED); - } - else - { - throw new IllegalStateException("Cannot delete port in " + state + " state"); - } - } - else if (desiredState == State.ACTIVE) - { - if ((state == State.INITIALISING || state == State.QUIESCED) && _state.compareAndSet(state, State.ACTIVE)) - { - try - { - onActivate(); - } - catch(RuntimeException e) - { - _state.compareAndSet(State.ACTIVE, State.ERRORED); - throw e; - } - return true; - } - else - { - throw new IllegalStateException("Cannot activate port in " + state + " state"); - } - } - else if (desiredState == State.QUIESCED) - { - if (state == State.INITIALISING && _state.compareAndSet(state, State.QUIESCED)) - { - return true; - } - } - else if (desiredState == State.STOPPED) - { - if (_state.compareAndSet(state, State.STOPPED)) - { - onStop(); - return true; - } - else - { - throw new IllegalStateException("Cannot stop port in " + state + " state"); - } - } - return false; - } - - protected void onActivate() - { - // no-op: expected to be overridden by subclass - } - - protected void onStop() - { - // no-op: expected to be overridden by subclass - } - - @Override - public AuthenticationProvider getAuthenticationProvider() - { - return _authenticationProvider; - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - Map<String, Object> converted = MapValueConverter.convert(attributes, ATTRIBUTE_TYPES); - - Map<String, Object> merged = generateEffectiveAttributes(converted); - - String newName = (String) merged.get(NAME); - if(!getName().equals(newName)) - { - throw new IllegalConfigurationException("Changing the port name is not allowed"); - } - - Integer newPort = (Integer) merged.get(PORT); - if(getPort() != newPort) - { - for(Port p : _broker.getPorts()) - { - if(p.getPort() == newPort) - { - throw new IllegalConfigurationException("Port number " + newPort + " is already in use by port " + p.getName()); - } - } - } - - @SuppressWarnings("unchecked") - Collection<Transport> transports = (Collection<Transport>)merged.get(TRANSPORTS); - @SuppressWarnings("unchecked") - Collection<Protocol> protocols = (Collection<Protocol>)merged.get(PROTOCOLS); - Boolean needClientCertificate = (Boolean)merged.get(NEED_CLIENT_AUTH); - Boolean wantClientCertificate = (Boolean)merged.get(WANT_CLIENT_AUTH); - boolean requiresCertificate = (needClientCertificate != null && needClientCertificate.booleanValue()) - || (wantClientCertificate != null && wantClientCertificate.booleanValue()); - - String keyStoreName = (String) merged.get(KEY_STORE); - if(keyStoreName != null) - { - if (_broker.findKeyStoreByName(keyStoreName) == null) - { - throw new IllegalConfigurationException("Can't find key store with name '" + keyStoreName + "' for port " + getName()); - } - } - - Set<String> trustStoreNames = (Set<String>) merged.get(TRUST_STORES); - boolean hasTrustStore = trustStoreNames != null && !trustStoreNames.isEmpty(); - if(hasTrustStore) - { - for (String trustStoreName : trustStoreNames) - { - if (_broker.findTrustStoreByName(trustStoreName) == null) - { - throw new IllegalConfigurationException("Cannot find trust store with name '" + trustStoreName + "'"); - } - } - } - - boolean usesSsl = transports != null && transports.contains(Transport.SSL); - if (usesSsl) - { - if (keyStoreName == null) - { - throw new IllegalConfigurationException("Can't create port which requires SSL but has no key store configured."); - } - - if (!hasTrustStore && requiresCertificate) - { - throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but has no trust store configured."); - } - } - else - { - if (requiresCertificate) - { - throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but doesn't use SSL transport."); - } - } - - if (protocols != null && protocols.contains(Protocol.RMI) && usesSsl) - { - throw new IllegalConfigurationException("Can't create RMI Registry port which requires SSL."); - } - - String authenticationProviderName = (String)merged.get(AUTHENTICATION_PROVIDER); - if (authenticationProviderName != null) - { - Collection<AuthenticationProvider> providers = _broker.getAuthenticationProviders(); - AuthenticationProvider provider = null; - for (AuthenticationProvider p : providers) - { - if (p.getName().equals(authenticationProviderName)) - { - provider = p; - break; - } - } - - if (provider == null) - { - throw new IllegalConfigurationException("Cannot find authentication provider with name '" - + authenticationProviderName + "'"); - } - } - else - { - if (protocols != null && !protocols.contains(Protocol.RMI)) - { - throw new IllegalConfigurationException("An authentication provider must be specified"); - } - } - - super.changeAttributes(converted); - } - - @Override - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - if(desiredState == State.DELETED) - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), Port.class, Operation.DELETE)) - { - throw new AccessControlException("Deletion of port is denied"); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), Port.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of port attributes is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), Port.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of port attributes is denied"); - } - } - - @Override - public KeyStore getKeyStore() - { - String keyStoreName = (String)getAttribute(Port.KEY_STORE); - KeyStore keyStore = _broker.findKeyStoreByName(keyStoreName); - - if (keyStoreName != null && keyStore == null) - { - throw new IllegalConfigurationException("Can't find key store with name '" + keyStoreName + "' for port " + getName()); - } - - return keyStore; - } - - @Override - public Collection<TrustStore> getTrustStores() - { - Set<String> trustStoreNames = (Set<String>) getAttribute(TRUST_STORES); - boolean hasTrustStoreName = trustStoreNames != null && !trustStoreNames.isEmpty(); - - final Collection<TrustStore> trustStores = new ArrayList<TrustStore>(); - if(hasTrustStoreName) - { - for (String name : trustStoreNames) - { - TrustStore trustStore = _broker.findTrustStoreByName(name); - if (trustStore == null) - { - throw new IllegalConfigurationException("Can't find trust store with name '" + name + "' for port " + getName()); - } - - trustStores.add(trustStore); - } - } - - return trustStores; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java deleted file mode 100644 index 8dc446e5b2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Protocol; -import org.apache.qpid.server.model.Protocol.ProtocolType; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.util.MapValueConverter; - -public class PortFactory -{ - public static final int DEFAULT_AMQP_SEND_BUFFER_SIZE = 262144; - public static final int DEFAULT_AMQP_RECEIVE_BUFFER_SIZE = 262144; - public static final boolean DEFAULT_AMQP_NEED_CLIENT_AUTH = false; - public static final boolean DEFAULT_AMQP_WANT_CLIENT_AUTH = false; - public static final boolean DEFAULT_AMQP_TCP_NO_DELAY = true; - public static final String DEFAULT_AMQP_BINDING = "*"; - public static final Transport DEFAULT_TRANSPORT = Transport.TCP; - - private final Collection<Protocol> _defaultProtocols; - - public PortFactory() - { - Set<Protocol> defaultProtocols = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, - Protocol.AMQP_0_10, Protocol.AMQP_1_0); - String excludedProtocols = System.getProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES); - if (excludedProtocols != null) - { - String[] excludes = excludedProtocols.split(","); - for (String exclude : excludes) - { - Protocol protocol = Protocol.valueOf(exclude); - defaultProtocols.remove(protocol); - } - } - String includedProtocols = System.getProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES); - if (includedProtocols != null) - { - String[] includes = includedProtocols.split(","); - for (String include : includes) - { - Protocol protocol = Protocol.valueOf(include); - defaultProtocols.add(protocol); - } - } - _defaultProtocols = Collections.unmodifiableCollection(defaultProtocols); - } - - public Port createPort(UUID id, Broker broker, Map<String, Object> attributes) - { - final Port port; - Map<String, Object> defaults = new HashMap<String, Object>(); - defaults.put(Port.TRANSPORTS, Collections.singleton(DEFAULT_TRANSPORT)); - Object portValue = attributes.get(Port.PORT); - if (portValue == null) - { - throw new IllegalConfigurationException("Port attribute is not specified for port: " + attributes); - } - Set<Protocol> protocols = MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, attributes, Protocol.class); - if (isAmqpProtocol(protocols, attributes)) - { - Object binding = attributes.get(Port.BINDING_ADDRESS); - if (binding == null) - { - binding = DEFAULT_AMQP_BINDING; - defaults.put(Port.BINDING_ADDRESS, DEFAULT_AMQP_BINDING); - } - defaults.put(Port.NAME, binding + ":" + portValue); - defaults.put(Port.PROTOCOLS, _defaultProtocols); - defaults.put(Port.TCP_NO_DELAY, DEFAULT_AMQP_TCP_NO_DELAY); - defaults.put(Port.WANT_CLIENT_AUTH, DEFAULT_AMQP_WANT_CLIENT_AUTH); - defaults.put(Port.NEED_CLIENT_AUTH, DEFAULT_AMQP_NEED_CLIENT_AUTH); - defaults.put(Port.RECEIVE_BUFFER_SIZE, DEFAULT_AMQP_RECEIVE_BUFFER_SIZE); - defaults.put(Port.SEND_BUFFER_SIZE, DEFAULT_AMQP_SEND_BUFFER_SIZE); - port = new AmqpPortAdapter(id, broker, attributes, defaults, broker.getTaskExecutor()); - - boolean useClientAuth = (Boolean) port.getAttribute(Port.NEED_CLIENT_AUTH) || (Boolean) port.getAttribute(Port.WANT_CLIENT_AUTH); - if(useClientAuth && port.getTrustStores().isEmpty()) - { - throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but has no trust stores configured."); - } - - if(useClientAuth && !port.getTransports().contains(Transport.SSL)) - { - throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but doesn't use SSL transport."); - } - } - else - { - if (protocols.size() > 1) - { - throw new IllegalConfigurationException("Only one protocol can be used on non AMQP port"); - } - Protocol protocol = protocols.iterator().next(); - - if(!broker.isManagementMode() && protocol.getProtocolType() != ProtocolType.HTTP) - { - //ManagementMode needs this relaxed to allow its overriding management ports to be inserted. - - //Enforce only a single port of each management protocol, as the plugins will only use one. - Collection<Port> existingPorts = broker.getPorts(); - for (Port existingPort : existingPorts) - { - Collection<Protocol> portProtocols = existingPort.getProtocols(); - if (portProtocols != null && portProtocols.contains(protocol)) - { - throw new IllegalConfigurationException("Port for protocol " + protocol + " already exists. Only one management port per protocol can be created."); - } - } - } - - defaults.put(Port.NAME, portValue + "-" + protocol.name()); - port = new PortAdapter(id, broker, attributes, defaults, broker.getTaskExecutor()); - - boolean rmiPort = port.getProtocols().contains(Protocol.RMI); - if (rmiPort && port.getTransports().contains(Transport.SSL)) - { - throw new IllegalConfigurationException("Can't create RMI registry port which requires SSL"); - } - } - - if(port.getTransports().contains(Transport.SSL)) - { - if(port.getKeyStore() == null) - { - throw new IllegalConfigurationException("Can't create port which requires SSL but has no key store configured."); - } - } - - return port; - } - - private boolean isAmqpProtocol(Set<Protocol> protocols, Map<String, Object> portAttributes) - { - if (protocols == null || protocols.isEmpty()) - { - // defaulting to AMQP if protocol is not specified - return true; - } - - Set<ProtocolType> protocolTypes = new HashSet<ProtocolType>(); - for (Protocol protocolObject : protocols) - { - protocolTypes.add(protocolObject.getProtocolType()); - } - - if (protocolTypes.size() > 1) - { - throw new IllegalConfigurationException("Found different protocol types '" + protocolTypes - + "' for port configuration: " + portAttributes); - } - - return protocolTypes.contains(ProtocolType.AMQP); - } - - public Collection<Protocol> getDefaultProtocols() - { - return _defaultProtocols; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PreferencesProviderCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PreferencesProviderCreator.java deleted file mode 100644 index 4bcca0e300..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PreferencesProviderCreator.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.qpid.server.model.adapter; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.plugin.PreferencesProviderFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class PreferencesProviderCreator -{ - private final Map<String, PreferencesProviderFactory> _factories; - private Collection<String> _supportedPreferencesProviders; - - public PreferencesProviderCreator() - { - QpidServiceLoader<PreferencesProviderFactory> preferencesProviderFactoriess = new QpidServiceLoader<PreferencesProviderFactory>(); - - Iterable<PreferencesProviderFactory> factories = preferencesProviderFactoriess - .instancesOf(PreferencesProviderFactory.class); - - Map<String, PreferencesProviderFactory> registeredPreferencesProviderFactories = new HashMap<String, PreferencesProviderFactory>(); - for (PreferencesProviderFactory factory : factories) - { - PreferencesProviderFactory existingFactory = registeredPreferencesProviderFactories.put(factory.getType(), - factory); - if (existingFactory != null) - { - throw new IllegalConfigurationException("Preferences provider factory of the same type '" - + factory.getType() + "' is already registered using class '" + existingFactory.getClass().getName() - + "', can not register class '" + factory.getClass().getName() + "'"); - } - } - _factories = registeredPreferencesProviderFactories; - _supportedPreferencesProviders = Collections.unmodifiableCollection(registeredPreferencesProviderFactories.keySet()); - } - - public Collection<String> getSupportedPreferencesProviders() - { - return _supportedPreferencesProviders; - } - - public PreferencesProvider create(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProvider) - { - return createPreferencesProvider(id, attributes, authenticationProvider); - } - - public PreferencesProvider recover(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProviderr) - { - return createPreferencesProvider(id, attributes, authenticationProviderr); - } - - private PreferencesProvider createPreferencesProvider(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProvider) - { - for (PreferencesProviderFactory factory : _factories.values()) - { - return factory.createInstance(id, attributes, authenticationProvider); - } - throw new IllegalConfigurationException("No group provider factory found for configuration attributes " + attributes); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java deleted file mode 100644 index 074f7c243b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java +++ /dev/null @@ -1,816 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.lang.reflect.Type; -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectFinder; -import org.apache.qpid.server.model.Consumer; -import org.apache.qpid.server.model.Exchange; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.model.QueueNotificationListener; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.protocol.AMQConnectionModel; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.queue.*; -import org.apache.qpid.server.store.DurableConfigurationStoreHelper; -import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.server.util.MapValueConverter; - -final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.SubscriptionRegistrationListener, AMQQueue.NotificationListener -{ - @SuppressWarnings("serial") - static final Map<String, Type> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Type>(){{ - put(ALERT_REPEAT_GAP, Long.class); - put(ALERT_THRESHOLD_MESSAGE_AGE, Long.class); - put(ALERT_THRESHOLD_MESSAGE_SIZE, Long.class); - put(ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, Long.class); - put(ALERT_THRESHOLD_QUEUE_DEPTH_BYTES, Long.class); - put(QUEUE_FLOW_CONTROL_SIZE_BYTES, Long.class); - put(QUEUE_FLOW_RESUME_SIZE_BYTES, Long.class); - put(MAXIMUM_DELIVERY_ATTEMPTS, Integer.class); - put(EXCLUSIVE, Boolean.class); - put(DESCRIPTION, String.class); - }}); - - private final AMQQueue _queue; - private final Map<Binding, BindingAdapter> _bindingAdapters = - new HashMap<Binding, BindingAdapter>(); - private Map<org.apache.qpid.server.subscription.Subscription, ConsumerAdapter> _consumerAdapters = - new HashMap<org.apache.qpid.server.subscription.Subscription, ConsumerAdapter>(); - - - private final VirtualHostAdapter _vhost; - private QueueStatisticsAdapter _statistics; - private QueueNotificationListener _queueNotificationListener; - - public QueueAdapter(final VirtualHostAdapter virtualHostAdapter, final AMQQueue queue) - { - super(queue.getId(), virtualHostAdapter.getTaskExecutor()); - _vhost = virtualHostAdapter; - addParent(org.apache.qpid.server.model.VirtualHost.class, virtualHostAdapter); - - _queue = queue; - _queue.addSubscriptionRegistrationListener(this); - populateConsumers(); - _statistics = new QueueStatisticsAdapter(queue); - _queue.setNotificationListener(this); - } - - /** - * Helper method to retrieve the SessionAdapter keyed by the AMQSessionModel. - * This method first finds the ConnectionAdapter associated with the Session from this QueueAdapter's parent vhost - * then it does a lookup on that to find the SessionAdapter keyed by the requested AMQSessionModel instance. - * @param session the AMQSessionModel used to index the SessionAdapter. - * @return the requested SessionAdapter or null if it can't be found. - */ - private SessionAdapter getSessionAdapter(AMQSessionModel session) - { - // Retrieve the ConnectionModel associated with the SessionModel as a key to lookup the ConnectionAdapter. - AMQConnectionModel connectionKey = session.getConnectionModel(); - - // Lookup the ConnectionAdapter, from which we should be able to retrieve the SessionAdapter we really want. - ConnectionAdapter connectionAdapter = _vhost.getConnectionAdapter(connectionKey); - if (connectionAdapter == null) - { - return null; // If we can't find an associated ConnectionAdapter the SessionAdapter is a lost cause. - } - else - { // With a good ConnectionAdapter we can finally try to find the SessionAdapter we are actually looking for. - SessionAdapter sessionAdapter = connectionAdapter.getSessionAdapter(session); - if (sessionAdapter == null) - { - return null; // If the SessionAdapter isn't associated with the selected ConnectionAdapter give up. - } - else - { - return sessionAdapter; - } - } - } - - private void populateConsumers() - { - Collection<org.apache.qpid.server.subscription.Subscription> actualSubscriptions = _queue.getConsumers(); - - synchronized (_consumerAdapters) - { - Iterator<org.apache.qpid.server.subscription.Subscription> iter = _consumerAdapters.keySet().iterator(); - for(org.apache.qpid.server.subscription.Subscription subscription : actualSubscriptions) - { - if(!_consumerAdapters.containsKey(subscription)) - { - SessionAdapter sessionAdapter = getSessionAdapter(subscription.getSessionModel()); - ConsumerAdapter adapter = new ConsumerAdapter(this, sessionAdapter, subscription); - _consumerAdapters.put(subscription, adapter); - if (sessionAdapter != null) - { // Register ConsumerAdapter with the SessionAdapter. - sessionAdapter.subscriptionRegistered(subscription, adapter); - } - } - } - } - } - - public Collection<org.apache.qpid.server.model.Binding> getBindings() - { - synchronized (_bindingAdapters) - { - return new ArrayList<org.apache.qpid.server.model.Binding>(_bindingAdapters.values()); - } - } - - public Collection<Consumer> getConsumers() - { - synchronized (_consumerAdapters) - { - return new ArrayList<Consumer>(_consumerAdapters.values()); - } - - } - - public void visit(final QueueEntryVisitor visitor) - { - _queue.visit(visitor); - } - - public void delete() - { - try - { - _queue.getVirtualHost().removeQueue(_queue); - } - catch(AMQException e) - { - throw new IllegalStateException(e); - } - } - - public String getName() - { - return _queue.getName(); - } - - public String setName(final String currentName, final String desiredName) - throws IllegalStateException, AccessControlException - { - return null; //TODO - } - - public State getActualState() - { - return null; //TODO - } - - public boolean isDurable() - { - return _queue.isDurable(); - } - - public void setDurable(final boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - //TODO - } - - public LifetimePolicy getLifetimePolicy() - { - return _queue.isAutoDelete() ? LifetimePolicy.AUTO_DELETE : LifetimePolicy.PERMANENT; - } - - public LifetimePolicy setLifetimePolicy(final LifetimePolicy expected, final LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return null; //TODO - } - - public long getTimeToLive() - { - return 0; //TODO - } - - public long setTimeToLive(final long expected, final long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return 0; //TODO - } - - - @Override - public Collection<String> getAttributeNames() - { - return Queue.AVAILABLE_ATTRIBUTES; - } - - @Override - public boolean changeAttribute(String name, Object expected, Object desired) throws IllegalStateException, AccessControlException, IllegalArgumentException - { - try - { - if(ALERT_REPEAT_GAP.equals(name)) - { - _queue.setMinimumAlertRepeatGap((Long)desired); - return true; - } - else if(ALERT_THRESHOLD_MESSAGE_AGE.equals(name)) - { - _queue.setMaximumMessageAge((Long)desired); - return true; - } - else if(ALERT_THRESHOLD_MESSAGE_SIZE.equals(name)) - { - _queue.setMaximumMessageSize((Long)desired); - return true; - } - else if(ALERT_THRESHOLD_QUEUE_DEPTH_BYTES.equals(name)) - { - _queue.setMaximumQueueDepth((Long)desired); - return true; - } - else if(ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES.equals(name)) - { - _queue.setMaximumMessageCount((Long)desired); - return true; - } - else if(ALTERNATE_EXCHANGE.equals(name)) - { - // In future we may want to accept a UUID as an alternative way to identifying the exchange - ExchangeAdapter alternateExchange = (ExchangeAdapter) desired; - _queue.setAlternateExchange(alternateExchange == null ? null : alternateExchange.getExchange()); - return true; - } - else if(EXCLUSIVE.equals(name)) - { - Boolean exclusiveFlag = (Boolean) desired; - _queue.setExclusive(exclusiveFlag); - return true; - } - else if(MESSAGE_GROUP_KEY.equals(name)) - { - // TODO - } - else if(MESSAGE_GROUP_SHARED_GROUPS.equals(name)) - { - // TODO - } - else if(LVQ_KEY.equals(name)) - { - // TODO - } - else if(MAXIMUM_DELIVERY_ATTEMPTS.equals(name)) - { - _queue.setMaximumDeliveryCount((Integer)desired); - return true; - } - else if(NO_LOCAL.equals(name)) - { - // TODO - } - else if(OWNER.equals(name)) - { - // TODO - } - else if(QUEUE_FLOW_CONTROL_SIZE_BYTES.equals(name)) - { - _queue.setCapacity((Long)desired); - return true; - } - else if(QUEUE_FLOW_RESUME_SIZE_BYTES.equals(name)) - { - _queue.setFlowResumeCapacity((Long)desired); - return true; - } - else if(QUEUE_FLOW_STOPPED.equals(name)) - { - // TODO - } - else if(SORT_KEY.equals(name)) - { - // TODO - } - else if(TYPE.equals(name)) - { - // TODO - } - else if (DESCRIPTION.equals(name)) - { - _queue.setDescription((String) desired); - return true; - } - - return super.changeAttribute(name, expected, desired); - } - finally - { - if (_queue.isDurable()) - { - try - { - DurableConfigurationStoreHelper.updateQueue(_queue.getVirtualHost().getDurableConfigurationStore(), - _queue); - } - catch (AMQStoreException e) - { - throw new IllegalStateException(e); - } - } - } - } - - @Override - public Object getAttribute(String name) - { - - if(ALERT_REPEAT_GAP.equals(name)) - { - return _queue.getMinimumAlertRepeatGap(); - } - else if(ALERT_THRESHOLD_MESSAGE_AGE.equals(name)) - { - return _queue.getMaximumMessageAge(); - } - else if(ALERT_THRESHOLD_MESSAGE_SIZE.equals(name)) - { - return _queue.getMaximumMessageSize(); - } - else if(ALERT_THRESHOLD_QUEUE_DEPTH_BYTES.equals(name)) - { - return _queue.getMaximumQueueDepth(); - } - else if(ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES.equals(name)) - { - return _queue.getMaximumMessageCount(); - } - else if(ALTERNATE_EXCHANGE.equals(name)) - { - org.apache.qpid.server.exchange.Exchange alternateExchange = _queue.getAlternateExchange(); - return alternateExchange == null ? null : - ConfiguredObjectFinder.findConfiguredObjectByName(_vhost.getExchanges(), - alternateExchange.getName()); - } - else if(EXCLUSIVE.equals(name)) - { - return _queue.isExclusive(); - } - else if(MESSAGE_GROUP_KEY.equals(name)) - { - return _queue.getAttribute(MESSAGE_GROUP_KEY); - } - else if(MESSAGE_GROUP_SHARED_GROUPS.equals(name)) - { - //We only return the boolean value if message groups are actually in use - return getAttribute(MESSAGE_GROUP_KEY) == null ? null : _queue.getAttribute(MESSAGE_GROUP_SHARED_GROUPS); - } - else if(LVQ_KEY.equals(name)) - { - if(_queue instanceof ConflationQueue) - { - return ((ConflationQueue)_queue).getConflationKey(); - } - } - else if(MAXIMUM_DELIVERY_ATTEMPTS.equals(name)) - { - return _queue.getMaximumDeliveryCount(); - } - else if(NO_LOCAL.equals(name)) - { - // TODO - } - else if(OWNER.equals(name)) - { - return _queue.getOwner(); - } - else if(QUEUE_FLOW_CONTROL_SIZE_BYTES.equals(name)) - { - return _queue.getCapacity(); - } - else if(QUEUE_FLOW_RESUME_SIZE_BYTES.equals(name)) - { - return _queue.getFlowResumeCapacity(); - } - else if(QUEUE_FLOW_STOPPED.equals(name)) - { - return _queue.isOverfull(); - } - else if(SORT_KEY.equals(name)) - { - if(_queue instanceof SortedQueue) - { - return ((SortedQueue)_queue).getSortedPropertyName(); - } - } - else if(TYPE.equals(name)) - { - if(_queue instanceof SortedQueue) - { - return "sorted"; - } - if(_queue instanceof ConflationQueue) - { - return "lvq"; - } - if(_queue instanceof AMQPriorityQueue) - { - return "priority"; - } - return "standard"; - } - else if(CREATED.equals(name)) - { - // TODO - } - else if(DURABLE.equals(name)) - { - return _queue.isDurable(); - } - else if(ID.equals(name)) - { - return getId(); - } - else if(LIFETIME_POLICY.equals(name)) - { - return _queue.isAutoDelete() ? LifetimePolicy.AUTO_DELETE : LifetimePolicy.PERMANENT; - } - else if(NAME.equals(name)) - { - return _queue.getName(); - } - else if(STATE.equals(name)) - { - return State.ACTIVE; // TODO - } - else if(TIME_TO_LIVE.equals(name)) - { - // TODO - } - else if(UPDATED.equals(name)) - { - // TODO - } - else if (DESCRIPTION.equals(name)) - { - return _queue.getDescription(); - } - else if(PRIORITIES.equals(name)) - { - if(_queue instanceof AMQPriorityQueue) - { - return ((AMQPriorityQueue)_queue).getPriorities(); - } - } - return super.getAttribute(name); - } - - public Statistics getStatistics() - { - return _statistics; - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if(clazz == Consumer.class) - { - return (Collection<C>) getConsumers(); - } - else if(clazz == org.apache.qpid.server.model.Binding.class) - { - return (Collection<C>) getBindings(); - } - else - { - return Collections.emptySet(); - } - } - - public org.apache.qpid.server.model.Binding createBinding(Exchange exchange, Map<String, Object> attributes) - throws AccessControlException, IllegalStateException - { - attributes = new HashMap<String, Object>(attributes); - String bindingKey = MapValueConverter.getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, ""); - Map<String, Object> bindingArgs = MapValueConverter.getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.<String,Object>emptyMap()); - - attributes.remove(org.apache.qpid.server.model.Binding.NAME); - attributes.remove(org.apache.qpid.server.model.Binding.ARGUMENTS); - - return exchange.createBinding(bindingKey, this, bindingArgs, attributes); - - } - - - - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - if(childClass == org.apache.qpid.server.model.Binding.class) - { - if(otherParents != null && otherParents.length == 1 && otherParents[0] instanceof Exchange) - { - Exchange exchange = (Exchange) otherParents[0]; - if(exchange.getParent(org.apache.qpid.server.model.VirtualHost.class) == getParent(org.apache.qpid.server.model.VirtualHost.class)) - { - return (C) createBinding(exchange, attributes); - } - else - { - throw new IllegalArgumentException("Queue and Exchange parents of a binding must be on same virtual host"); - } - } - else - { - throw new IllegalArgumentException("Other parent must be an exchange"); - } - } - else - { - throw new IllegalArgumentException(); - } - } - - void bindingRegistered(Binding binding, BindingAdapter adapter) - { - synchronized (_bindingAdapters) - { - _bindingAdapters.put(binding, adapter); - } - childAdded(adapter); - } - - void bindingUnregistered(Binding binding) - { - BindingAdapter adapter = null; - synchronized (_bindingAdapters) - { - adapter = _bindingAdapters.remove(binding); - } - if(adapter != null) - { - childRemoved(adapter); - } - } - - AMQQueue getAMQQueue() - { - return _queue; - } - - public void subscriptionRegistered(final AMQQueue queue, final Subscription subscription) - { - ConsumerAdapter adapter = null; - synchronized (_consumerAdapters) - { - if(!_consumerAdapters.containsKey(subscription)) - { - SessionAdapter sessionAdapter = getSessionAdapter(subscription.getSessionModel()); - adapter = new ConsumerAdapter(this, sessionAdapter, subscription); - _consumerAdapters.put(subscription, adapter); - if (sessionAdapter != null) - { // Register ConsumerAdapter with the SessionAdapter. - sessionAdapter.subscriptionRegistered(subscription, adapter); - } - } - } - if(adapter != null) - { - childAdded(adapter); - } - } - - public void subscriptionUnregistered(final AMQQueue queue, final Subscription subscription) - { - ConsumerAdapter adapter = null; - - synchronized (_consumerAdapters) - { - adapter = _consumerAdapters.remove(subscription); - } - if(adapter != null) - { - SessionAdapter sessionAdapter = getSessionAdapter(subscription.getSessionModel()); - if (sessionAdapter != null) - { // Unregister ConsumerAdapter with the SessionAdapter. - sessionAdapter.subscriptionUnregistered(subscription); - } - childRemoved(adapter); - } - } - - VirtualHostAdapter getVirtualHost() - { - return _vhost; - } - - - private static class QueueStatisticsAdapter implements Statistics - { - - private final AMQQueue _queue; - - public QueueStatisticsAdapter(AMQQueue queue) - { - _queue = queue; - } - - public Collection<String> getStatisticNames() - { - return Queue.AVAILABLE_STATISTICS; - } - - public Object getStatistic(String name) - { - if(BINDING_COUNT.equals(name)) - { - return _queue.getBindingCount(); - } - else if(CONSUMER_COUNT.equals(name)) - { - return _queue.getConsumerCount(); - } - else if(CONSUMER_COUNT_WITH_CREDIT.equals(name)) - { - return _queue.getActiveConsumerCount(); - } - else if(DISCARDS_TTL_BYTES.equals(name)) - { - return null; // TODO - } - else if(DISCARDS_TTL_MESSAGES.equals(name)) - { - return null; // TODO - } - else if(PERSISTENT_DEQUEUED_BYTES.equals(name)) - { - return _queue.getPersistentByteDequeues(); - } - else if(PERSISTENT_DEQUEUED_MESSAGES.equals(name)) - { - return _queue.getPersistentMsgDequeues(); - } - else if(PERSISTENT_ENQUEUED_BYTES.equals(name)) - { - return _queue.getPersistentByteEnqueues(); - } - else if(PERSISTENT_ENQUEUED_MESSAGES.equals(name)) - { - return _queue.getPersistentMsgEnqueues(); - } - else if(QUEUE_DEPTH_BYTES.equals(name)) - { - return _queue.getQueueDepth(); - } - else if(QUEUE_DEPTH_MESSAGES.equals(name)) - { - return _queue.getMessageCount(); - } - else if(STATE_CHANGED.equals(name)) - { - return null; // TODO - } - else if(TOTAL_DEQUEUED_BYTES.equals(name)) - { - return _queue.getTotalDequeueSize(); - } - else if(TOTAL_DEQUEUED_MESSAGES.equals(name)) - { - return _queue.getTotalDequeueCount(); - } - else if(TOTAL_ENQUEUED_BYTES.equals(name)) - { - return _queue.getTotalEnqueueSize(); - } - else if(TOTAL_ENQUEUED_MESSAGES.equals(name)) - { - return _queue.getTotalEnqueueCount(); - } - else if(UNACKNOWLEDGED_BYTES.equals(name)) - { - return _queue.getUnackedMessageBytes(); - } - else if(UNACKNOWLEDGED_MESSAGES.equals(name)) - { - return _queue.getUnackedMessageCount(); - } - - return null; - } - } - - @Override - public void setNotificationListener(QueueNotificationListener listener) - { - _queueNotificationListener = listener; - } - - @Override - public void notifyClients(NotificationCheck notification, AMQQueue queue, String notificationMsg) - { - QueueNotificationListener listener = _queueNotificationListener; - if(listener != null) - { - listener.notifyClients(notification, this, notificationMsg); - } - } - - @Override - protected boolean setState(State currentState, State desiredState) throws IllegalStateTransitionException, - AccessControlException - { - if (desiredState == State.DELETED) - { - delete(); - return true; - } - return false; - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_vhost.getSecurityManager().authoriseUpdate(_queue)) - { - throw new AccessControlException("Setting of queue attribute is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_vhost.getSecurityManager().authoriseUpdate(_queue)) - { - throw new AccessControlException("Setting of queue attributes is denied"); - } - } - - @Override - protected void changeAttributes(final Map<String, Object> attributes) - { - Map<String, Object> convertedAttributes = MapValueConverter.convert(attributes, ATTRIBUTE_TYPES); - validateAttributes(convertedAttributes); - - super.changeAttributes(convertedAttributes); - } - - private void validateAttributes(Map<String, Object> convertedAttributes) - { - Long queueFlowControlSize = (Long) convertedAttributes.get(QUEUE_FLOW_CONTROL_SIZE_BYTES); - Long queueFlowControlResumeSize = (Long) convertedAttributes.get(QUEUE_FLOW_RESUME_SIZE_BYTES); - if (queueFlowControlSize != null || queueFlowControlResumeSize != null ) - { - if (queueFlowControlSize == null) - { - queueFlowControlSize = (Long)getAttribute(QUEUE_FLOW_CONTROL_SIZE_BYTES); - } - if (queueFlowControlResumeSize == null) - { - queueFlowControlResumeSize = (Long)getAttribute(QUEUE_FLOW_RESUME_SIZE_BYTES); - } - if (queueFlowControlResumeSize > queueFlowControlSize) - { - throw new IllegalConfigurationException("Flow resume size can't be greater than flow control size"); - } - } - for (Map.Entry<String, Object> entry: convertedAttributes.entrySet()) - { - Object value = entry.getValue(); - if (value instanceof Number && ((Number)value).longValue() < 0) - { - throw new IllegalConfigurationException("Only positive integer value can be specified for the attribute " - + entry.getKey()); - } - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java deleted file mode 100644 index 31ce7e56fd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; - -import java.util.Map; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Publisher; -import org.apache.qpid.server.model.Session; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.Consumer; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.protocol.AMQSessionModel; - -final class SessionAdapter extends AbstractAdapter implements Session -{ - // Attributes - - - private AMQSessionModel _session; - private SessionStatistics _statistics; - private Map<Subscription, ConsumerAdapter> _consumerAdapters = new HashMap<Subscription, ConsumerAdapter>(); - - public SessionAdapter(final AMQSessionModel session, TaskExecutor taskExecutor) - { - super(UUIDGenerator.generateRandomUUID(), taskExecutor); - _session = session; - _statistics = new SessionStatistics(); - } - - public Collection<Consumer> getSubscriptions() - { - synchronized (_consumerAdapters) - { - return new ArrayList<Consumer>(_consumerAdapters.values()); - } - } - - public Collection<Publisher> getPublishers() - { - return null; //TODO - } - - public String getName() - { - return String.valueOf(_session.getChannelId()); - } - - public String setName(final String currentName, final String desiredName) - throws IllegalStateException, AccessControlException - { - return null; //TODO - } - - public State getActualState() - { - return null; //TODO - } - - public boolean isDurable() - { - return false; //TODO - } - - public void setDurable(final boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - //TODO - } - - public LifetimePolicy getLifetimePolicy() - { - return null; //TODO - } - - public LifetimePolicy setLifetimePolicy(final LifetimePolicy expected, final LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return null; //TODO - } - - public long getTimeToLive() - { - return 0; //TODO - } - - public long setTimeToLive(final long expected, final long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - return 0; //TODO - } - - /** - * Register a ConsumerAdapter (Subscription) with this Session keyed by the Subscription. - * @param subscription the org.apache.qpid.server.subscription.Subscription used to key the ConsumerAdapter. - * @param adapter the registered ConsumerAdapter. - */ - void subscriptionRegistered(Subscription subscription, ConsumerAdapter adapter) - { - synchronized (_consumerAdapters) - { - _consumerAdapters.put(subscription, adapter); - } - childAdded(adapter); - } - - /** - * Unregister a ConsumerAdapter (Subscription) with this Session keyed by the Subscription. - * @param subscription the org.apache.qpid.server.subscription.Subscription used to key the ConsumerAdapter. - */ - void subscriptionUnregistered(Subscription subscription) - { - ConsumerAdapter adapter = null; - synchronized (_consumerAdapters) - { - adapter = _consumerAdapters.remove(subscription); - } - if (adapter != null) - { - childRemoved(adapter); - } - } - - @Override - public Collection<String> getAttributeNames() - { - Collection<String> names = new HashSet<String>(super.getAttributeNames()); - names.addAll(AVAILABLE_ATTRIBUTES); - - return Collections.unmodifiableCollection(names); - } - - @Override - public Object getAttribute(String name) - { - if(name.equals(ID)) - { - return getId(); - } - else if (name.equals(NAME)) - { - return getName(); - } - else if(name.equals(CHANNEL_ID)) - { - return _session.getChannelId(); - } - else if(name.equals(PRODUCER_FLOW_BLOCKED)) - { - return _session.getBlocking(); - } - return super.getAttribute(name); //TODO - Implement - } - - public Statistics getStatistics() - { - return _statistics; - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if(clazz == Consumer.class) - { - return (Collection<C>) getSubscriptions(); - } - else if(clazz == Publisher.class) - { - return (Collection<C>) getPublishers(); - } - else - { - return Collections.emptySet(); - } - } - - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - throw new UnsupportedOperationException(); - } - - private class SessionStatistics implements Statistics - { - - public SessionStatistics() - { - } - - public Collection<String> getStatisticNames() - { - return AVAILABLE_STATISTICS; - } - - public Object getStatistic(String name) - { - if(name.equals(BYTES_IN)) - { - } - else if(name.equals(BYTES_OUT)) - { - } - else if(name.equals(CONSUMER_COUNT)) - { - return _session.getConsumerCount(); - } - else if(name.equals(LOCAL_TRANSACTION_BEGINS)) - { - return _session.getTxnStart(); - } - else if(name.equals(LOCAL_TRANSACTION_OPEN)) - { - long open = _session.getTxnStart() - (_session.getTxnCommits() + _session.getTxnRejects()); - return (Boolean) (open > 0l); - } - else if(name.equals(LOCAL_TRANSACTION_ROLLBACKS)) - { - return _session.getTxnRejects(); - } - else if(name.equals(STATE_CHANGED)) - { - } - else if(name.equals(UNACKNOWLEDGED_BYTES)) - { - } - else if(name.equals(UNACKNOWLEDGED_MESSAGES)) - { - return _session.getUnacknowledgedMessageCount(); - } - else if(name.equals(XA_TRANSACTION_BRANCH_ENDS)) - { - } - else if(name.equals(XA_TRANSACTION_BRANCH_STARTS)) - { - } - else if(name.equals(XA_TRANSACTION_BRANCH_SUSPENDS)) - { - - } - - return null; // TODO - Implement - } - } - - @Override - protected boolean setState(State currentState, State desiredState) - { - // TODO : add state management - return false; - } - - @Override - public Object setAttribute(final String name, final Object expected, final Object desired) throws IllegalStateException, - AccessControlException, IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on session is not supported."); - } - - @Override - public void setAttributes(final Map<String, Object> attributes) throws IllegalStateException, AccessControlException, - IllegalArgumentException - { - throw new UnsupportedOperationException("Changing attributes on session is not supported."); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/StatisticsAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/StatisticsAdapter.java deleted file mode 100644 index 28c46a0339..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/StatisticsAdapter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.qpid.server.model.adapter; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.stats.StatisticsCounter; -import org.apache.qpid.server.stats.StatisticsGatherer; - -class StatisticsAdapter implements Statistics -{ - - private final Map<String, StatisticsCounter> _statistics = - new HashMap<String, StatisticsCounter>(); - - - private static final String BYTES_IN = "bytesIn"; - private static final String BYTES_OUT = "bytesOut"; - private static final String MESSAGES_IN = "messagesIn"; - private static final String MESSAGES_OUT = "messagesOut"; - - private static final Collection<String> STATISTIC_NAMES = - Collections.unmodifiableCollection(Arrays.asList(BYTES_IN, BYTES_OUT, MESSAGES_IN, MESSAGES_OUT)); - - - - public StatisticsAdapter(StatisticsGatherer statGatherer) - { - _statistics.put(BYTES_OUT, statGatherer.getDataDeliveryStatistics()); - _statistics.put(BYTES_IN, statGatherer.getDataReceiptStatistics()); - _statistics.put(MESSAGES_OUT, statGatherer.getMessageDeliveryStatistics()); - _statistics.put(MESSAGES_IN, statGatherer.getMessageReceiptStatistics()); - } - - - public Collection<String> getStatisticNames() - { - return STATISTIC_NAMES; - } - - public Object getStatistic(String name) - { - StatisticsCounter counter = _statistics.get(name); - return counter == null ? null : counter.getTotal(); - - } - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java deleted file mode 100644 index 5e7bfff4de..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.security.AccessControlException; -import java.security.GeneralSecurityException; -import java.security.KeyStore; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; - -import javax.net.ssl.X509TrustManager; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.IntegrityViolationException; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.util.MapValueConverter; -import org.apache.qpid.transport.network.security.ssl.QpidMultipleTrustManager; -import org.apache.qpid.transport.network.security.ssl.QpidPeersOnlyTrustManager; -import org.apache.qpid.transport.network.security.ssl.SSLUtil; - -public class TrustStoreAdapter extends AbstractKeyStoreAdapter implements TrustStore -{ - @SuppressWarnings("serial") - public static final Map<String, Type> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Type>(){{ - put(NAME, String.class); - put(PATH, String.class); - put(PASSWORD, String.class); - put(TYPE, String.class); - put(PEERS_ONLY, Boolean.class); - put(TRUST_MANAGER_FACTORY_ALGORITHM, String.class); - }}); - - @SuppressWarnings("serial") - public static final Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>(){{ - put(TrustStore.TYPE, DEFAULT_KEYSTORE_TYPE); - put(TrustStore.PEERS_ONLY, Boolean.FALSE); - put(TrustStore.TRUST_MANAGER_FACTORY_ALGORITHM, TrustManagerFactory.getDefaultAlgorithm()); - }}); - - private Broker _broker; - - public TrustStoreAdapter(UUID id, Broker broker, Map<String, Object> attributes) - { - super(id, broker, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES)); - _broker = broker; - - String trustStorePath = (String) getAttribute(TrustStore.PATH); - String trustStorePassword = getPassword(); - String trustStoreType = (String) getAttribute(TrustStore.TYPE); - String trustManagerFactoryAlgorithm = (String) getAttribute(TrustStore.TRUST_MANAGER_FACTORY_ALGORITHM); - - validateTrustStoreAttributes(trustStoreType, trustStorePath, - trustStorePassword, trustManagerFactoryAlgorithm); - } - - @Override - public Collection<String> getAttributeNames() - { - return AVAILABLE_ATTRIBUTES; - } - - @Override - protected boolean setState(State currentState, State desiredState) - { - if(desiredState == State.DELETED) - { - // verify that it is not in use - String storeName = getName(); - - Collection<Port> ports = new ArrayList<Port>(_broker.getPorts()); - for (Port port : ports) - { - Collection<TrustStore> trustStores = port.getTrustStores(); - for(TrustStore store : trustStores) - { - if (storeName.equals(store.getAttribute(TrustStore.NAME))) - { - throw new IntegrityViolationException("Trust store '" + storeName + "' can't be deleted as it is in use by a port: " + port.getName()); - } - } - } - - return true; - } - - return false; - } - - @Override - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - if(desiredState == State.DELETED) - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), TrustStore.class, Operation.DELETE)) - { - throw new AccessControlException("Deletion of key store is denied"); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - authoriseSetAttribute(); - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - authoriseSetAttribute(); - } - - private void authoriseSetAttribute() - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), TrustStore.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting key store attributes is denied"); - } - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - Map<String, Object> changedValues = MapValueConverter.convert(attributes, ATTRIBUTE_TYPES); - if(changedValues.containsKey(TrustStore.NAME)) - { - String newName = (String) changedValues.get(TrustStore.NAME); - if(!getName().equals(newName)) - { - throw new IllegalConfigurationException("Changing the trust store name is not allowed"); - } - } - - Map<String, Object> merged = generateEffectiveAttributes(changedValues); - - String trustStorePath = (String)merged.get(TrustStore.PATH); - String trustStorePassword = (String) merged.get(TrustStore.PASSWORD); - String trustStoreType = (String)merged.get(TrustStore.TYPE); - String trustManagerFactoryAlgorithm = (String)merged.get(TrustStore.TRUST_MANAGER_FACTORY_ALGORITHM); - - validateTrustStoreAttributes(trustStoreType, trustStorePath, - trustStorePassword, trustManagerFactoryAlgorithm); - - super.changeAttributes(changedValues); - } - - private void validateTrustStoreAttributes(String type, String trustStorePath, - String password, String trustManagerFactoryAlgorithm) - { - try - { - SSLUtil.getInitializedKeyStore(trustStorePath, password, type); - } - catch (Exception e) - { - throw new IllegalConfigurationException("Cannot instantiate trust store at " + trustStorePath, e); - } - - try - { - TrustManagerFactory.getInstance(trustManagerFactoryAlgorithm); - } - catch (NoSuchAlgorithmException e) - { - throw new IllegalConfigurationException("Unknown trustManagerFactoryAlgorithm: " + trustManagerFactoryAlgorithm); - } - } - - public TrustManager[] getTrustManagers() throws GeneralSecurityException - { - String trustStorePath = (String)getAttribute(TrustStore.PATH); - String trustStorePassword = getPassword(); - String trustStoreType = (String)getAttribute(TrustStore.TYPE); - String trustManagerFactoryAlgorithm = (String)getAttribute(TrustStore.TRUST_MANAGER_FACTORY_ALGORITHM); - - try - { - KeyStore ts = SSLUtil.getInitializedKeyStore(trustStorePath, trustStorePassword, trustStoreType); - final TrustManagerFactory tmf = TrustManagerFactory - .getInstance(trustManagerFactoryAlgorithm); - tmf.init(ts); - final Collection<TrustManager> trustManagersCol = new ArrayList<TrustManager>(); - final QpidMultipleTrustManager mulTrustManager = new QpidMultipleTrustManager(); - TrustManager[] delegateManagers = tmf.getTrustManagers(); - for (TrustManager tm : delegateManagers) - { - if (tm instanceof X509TrustManager) - { - if (Boolean.TRUE.equals(getAttribute(PEERS_ONLY))) - { - // truststore is supposed to trust only clients which peers certificates - // are directly in the store. CA signing will not be considered. - mulTrustManager.addTrustManager(new QpidPeersOnlyTrustManager(ts, (X509TrustManager) tm)); - } - else - { - mulTrustManager.addTrustManager((X509TrustManager) tm); - } - } - else - { - trustManagersCol.add(tm); - } - } - if (! mulTrustManager.isEmpty()) - { - trustManagersCol.add(mulTrustManager); - } - - if (trustManagersCol.isEmpty()) - { - return null; - } - else - { - return trustManagersCol.toArray(new TrustManager[trustManagersCol.size()]); - } - } - catch (IOException e) - { - throw new GeneralSecurityException(e); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java deleted file mode 100644 index 58b0b76735..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java +++ /dev/null @@ -1,1273 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.io.File; -import java.lang.reflect.Type; -import java.security.AccessControlException; -import java.security.Principal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.commons.configuration.SystemConfiguration; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.VirtualHostConfiguration; -import org.apache.qpid.server.configuration.XmlConfigurationUtilities.MyConfiguration; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Connection; -import org.apache.qpid.server.model.Exchange; -import org.apache.qpid.server.model.IntegrityViolationException; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Protocol; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.model.QueueType; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.model.VirtualHostAlias; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.protocol.AMQConnectionModel; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.AMQQueueFactory; -import org.apache.qpid.server.queue.QueueArgumentsConverter; -import org.apache.qpid.server.queue.QueueEntry; -import org.apache.qpid.server.queue.SimpleAMQQueue; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.security.auth.AuthenticatedPrincipal; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.txn.LocalTransaction; -import org.apache.qpid.server.txn.ServerTransaction; -import org.apache.qpid.server.util.MapValueConverter; -import org.apache.qpid.server.plugin.VirtualHostFactory; -import org.apache.qpid.server.virtualhost.ExchangeExistsException; -import org.apache.qpid.server.virtualhost.ReservedExchangeNameException; -import org.apache.qpid.server.virtualhost.UnknownExchangeException; -import org.apache.qpid.server.virtualhost.VirtualHostListener; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; -import org.apache.qpid.server.virtualhost.plugins.QueueExistsException; - -public final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, VirtualHostListener -{ - private static final Logger LOGGER = Logger.getLogger(VirtualHostAdapter.class); - - @SuppressWarnings("serial") - public static final Map<String, Type> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Type>(){{ - put(NAME, String.class); - put(TYPE, String.class); - put(STORE_PATH, String.class); - put(STORE_TYPE, String.class); - put(CONFIG_PATH, String.class); - put(STATE, State.class); - }}); - - private org.apache.qpid.server.virtualhost.VirtualHost _virtualHost; - - private final Map<AMQConnectionModel, ConnectionAdapter> _connectionAdapters = - new HashMap<AMQConnectionModel, ConnectionAdapter>(); - - private final Map<AMQQueue, QueueAdapter> _queueAdapters = - new HashMap<AMQQueue, QueueAdapter>(); - - private final Map<org.apache.qpid.server.exchange.Exchange, ExchangeAdapter> _exchangeAdapters = - new HashMap<org.apache.qpid.server.exchange.Exchange, ExchangeAdapter>(); - private StatisticsAdapter _statistics; - private final Broker _broker; - private final List<VirtualHostAlias> _aliases = new ArrayList<VirtualHostAlias>(); - private StatisticsGatherer _brokerStatisticsGatherer; - - public VirtualHostAdapter(UUID id, Map<String, Object> attributes, Broker broker, StatisticsGatherer brokerStatisticsGatherer, TaskExecutor taskExecutor) - { - super(id, null, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES, false), taskExecutor, false); - _broker = broker; - _brokerStatisticsGatherer = brokerStatisticsGatherer; - validateAttributes(); - addParent(Broker.class, broker); - } - - private void validateAttributes() - { - String name = getName(); - if (name == null || "".equals(name.trim())) - { - throw new IllegalConfigurationException("Virtual host name must be specified"); - } - - String configurationFile = (String) getAttribute(CONFIG_PATH); - String type = (String) getAttribute(TYPE); - - boolean invalidAttributes = false; - if (configurationFile == null) - { - if (type == null) - { - invalidAttributes = true; - } - else - { - validateAttributes(type); - } - }/* - else - { - if (type != null) - { - invalidAttributes = true; - } - - }*/ - if (invalidAttributes) - { - throw new IllegalConfigurationException("Please specify either the 'configPath' attribute or 'type' attributes"); - } - - // pre-load the configuration in order to validate - try - { - createVirtualHostConfiguration(name); - } - catch(ConfigurationException e) - { - throw new IllegalConfigurationException("Failed to validate configuration", e); - } - } - - private void validateAttributes(String type) - { - final VirtualHostFactory factory = VirtualHostFactory.FACTORIES.get(type); - if(factory == null) - { - throw new IllegalArgumentException("Unknown virtual host type '"+ type +"'. Valid types are: " + VirtualHostFactory.TYPES.get()); - } - factory.validateAttributes(getActualAttributes()); - - } - - private void populateExchanges() - { - Collection<org.apache.qpid.server.exchange.Exchange> actualExchanges = - _virtualHost.getExchanges(); - - synchronized (_exchangeAdapters) - { - for(org.apache.qpid.server.exchange.Exchange exchange : actualExchanges) - { - if(!_exchangeAdapters.containsKey(exchange)) - { - _exchangeAdapters.put(exchange, new ExchangeAdapter(this,exchange)); - } - } - } - } - - - private void populateQueues() - { - Collection<AMQQueue> actualQueues = _virtualHost.getQueues(); - if ( actualQueues != null ) - { - synchronized(_queueAdapters) - { - for(AMQQueue queue : actualQueues) - { - if(!_queueAdapters.containsKey(queue)) - { - _queueAdapters.put(queue, new QueueAdapter(this, queue)); - } - } - } - } - } - - public Collection<VirtualHostAlias> getAliases() - { - return Collections.unmodifiableCollection(_aliases); - } - - public Collection<Connection> getConnections() - { - synchronized(_connectionAdapters) - { - return new ArrayList<Connection>(_connectionAdapters.values()); - } - - } - - /** - * Retrieve the ConnectionAdapter instance keyed by the AMQConnectionModel from this VirtualHost. - * @param connection the AMQConnectionModel used to index the ConnectionAdapter. - * @return the requested ConnectionAdapter. - */ - ConnectionAdapter getConnectionAdapter(AMQConnectionModel connection) - { - synchronized (_connectionAdapters) - { - return _connectionAdapters.get(connection); - } - } - - public Collection<Queue> getQueues() - { - synchronized(_queueAdapters) - { - return new ArrayList<Queue>(_queueAdapters.values()); - } - } - - public Collection<Exchange> getExchanges() - { - synchronized (_exchangeAdapters) - { - return new ArrayList<Exchange>(_exchangeAdapters.values()); - } - } - - - public Exchange createExchange(Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException - { - attributes = new HashMap<String, Object>(attributes); - - String name = MapValueConverter.getStringAttribute(Exchange.NAME, attributes, null); - State state = MapValueConverter.getEnumAttribute(State.class, Exchange.STATE, attributes, State.ACTIVE); - boolean durable = MapValueConverter.getBooleanAttribute(Exchange.DURABLE, attributes, false); - LifetimePolicy lifetime = MapValueConverter.getEnumAttribute(LifetimePolicy.class, Exchange.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT); - String type = MapValueConverter.getStringAttribute(Exchange.TYPE, attributes, null); - long ttl = MapValueConverter.getLongAttribute(Exchange.TIME_TO_LIVE, attributes, 0l); - - attributes.remove(Exchange.NAME); - attributes.remove(Exchange.STATE); - attributes.remove(Exchange.DURABLE); - attributes.remove(Exchange.LIFETIME_POLICY); - attributes.remove(Exchange.TYPE); - attributes.remove(Exchange.TIME_TO_LIVE); - - return createExchange(name, state, durable, lifetime, ttl, type, attributes); - } - - public Exchange createExchange(final String name, - final State initialState, - final boolean durable, - final LifetimePolicy lifetime, - final long ttl, - final String type, - final Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException - { - checkVHostStateIsActive(); - - try - { - String alternateExchange = null; - if(attributes.containsKey(Exchange.ALTERNATE_EXCHANGE)) - { - Object altExchangeObject = attributes.get(Exchange.ALTERNATE_EXCHANGE); - if(altExchangeObject instanceof Exchange) - { - alternateExchange = ((Exchange) altExchangeObject).getName(); - } - else if(altExchangeObject instanceof UUID) - { - for(Exchange ex : getExchanges()) - { - if(altExchangeObject.equals(ex.getId())) - { - alternateExchange = ex.getName(); - break; - } - } - } - else if(altExchangeObject instanceof String) - { - - for(Exchange ex : getExchanges()) - { - if(altExchangeObject.equals(ex.getName())) - { - alternateExchange = ex.getName(); - break; - } - } - if(alternateExchange == null) - { - try - { - UUID id = UUID.fromString(altExchangeObject.toString()); - for(Exchange ex : getExchanges()) - { - if(id.equals(ex.getId())) - { - alternateExchange = ex.getName(); - break; - } - } - } - catch(IllegalArgumentException e) - { - // ignore - } - - } - } - } - org.apache.qpid.server.exchange.Exchange exchange = _virtualHost.createExchange(null, - name, - type, - durable, - lifetime == LifetimePolicy.AUTO_DELETE, - alternateExchange); - synchronized (_exchangeAdapters) - { - return _exchangeAdapters.get(exchange); - } - - } - catch(ExchangeExistsException e) - { - throw new IllegalArgumentException("Exchange with name '" + name + "' already exists"); - } - catch(ReservedExchangeNameException e) - { - throw new UnsupportedOperationException("'" + name + "' is a reserved exchange name"); - } - catch(UnknownExchangeException e) - { - throw new IllegalArgumentException("Alternate Exchange with name '" + e.getExchangeName() + "' does not exist"); - } - catch(AMQException e) - { - throw new IllegalArgumentException(e); - } - } - - public Queue createQueue(Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException - { - attributes = new HashMap<String, Object>(attributes); - - if (attributes.containsKey(Queue.TYPE)) - { - String typeAttribute = MapValueConverter.getStringAttribute(Queue.TYPE, attributes, null); - QueueType queueType = null; - try - { - queueType = QueueType.valueOf(typeAttribute.toUpperCase()); - } - catch(Exception e) - { - throw new IllegalArgumentException("Unsupported queue type :" + typeAttribute); - } - if (queueType == QueueType.LVQ && attributes.get(Queue.LVQ_KEY) == null) - { - attributes.put(Queue.LVQ_KEY, AMQQueueFactory.QPID_DEFAULT_LVQ_KEY); - } - else if (queueType == QueueType.PRIORITY && attributes.get(Queue.PRIORITIES) == null) - { - attributes.put(Queue.PRIORITIES, 10); - } - else if (queueType == QueueType.SORTED && attributes.get(Queue.SORT_KEY) == null) - { - throw new IllegalArgumentException("Sort key is not specified for sorted queue"); - } - } - - if (attributes.containsKey(Queue.MESSAGE_GROUP_KEY)) - { - String key = MapValueConverter.getStringAttribute(Queue.MESSAGE_GROUP_KEY, attributes); - attributes.remove(Queue.MESSAGE_GROUP_KEY); - attributes.put(QueueArgumentsConverter.QPID_GROUP_HEADER_KEY, key); - } - - if (attributes.containsKey(Queue.MESSAGE_GROUP_SHARED_GROUPS)) - { - if(MapValueConverter.getBooleanAttribute(Queue.MESSAGE_GROUP_SHARED_GROUPS, attributes)) - { - attributes.remove(Queue.MESSAGE_GROUP_SHARED_GROUPS); - attributes.put(QueueArgumentsConverter.QPID_SHARED_MSG_GROUP, SimpleAMQQueue.SHARED_MSG_GROUP_ARG_VALUE); - } - } - - String name = MapValueConverter.getStringAttribute(Queue.NAME, attributes, null); - State state = MapValueConverter.getEnumAttribute(State.class, Queue.STATE, attributes, State.ACTIVE); - boolean durable = MapValueConverter.getBooleanAttribute(Queue.DURABLE, attributes, false); - LifetimePolicy lifetime = MapValueConverter.getEnumAttribute(LifetimePolicy.class, Queue.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT); - long ttl = MapValueConverter.getLongAttribute(Queue.TIME_TO_LIVE, attributes, 0l); - boolean exclusive= MapValueConverter.getBooleanAttribute(Queue.EXCLUSIVE, attributes, false); - - attributes.remove(Queue.NAME); - attributes.remove(Queue.STATE); - attributes.remove(Queue.DURABLE); - attributes.remove(Queue.LIFETIME_POLICY); - attributes.remove(Queue.TIME_TO_LIVE); - - return createQueue(name, state, durable, exclusive, lifetime, ttl, attributes); - } - - public Queue createQueue(final String name, - final State initialState, - final boolean durable, - boolean exclusive, - final LifetimePolicy lifetime, - final long ttl, - final Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException - { - checkVHostStateIsActive(); - - String owner = null; - if(exclusive) - { - Principal authenticatedPrincipal = AuthenticatedPrincipal.getOptionalAuthenticatedPrincipalFromSubject(SecurityManager.getThreadSubject()); - if(authenticatedPrincipal != null) - { - owner = authenticatedPrincipal.getName(); - } - } - - final boolean autoDelete = lifetime == LifetimePolicy.AUTO_DELETE; - - try - { - - AMQQueue queue = - _virtualHost.createQueue(UUIDGenerator.generateQueueUUID(name, _virtualHost.getName()), name, - durable, owner, autoDelete, exclusive, autoDelete && exclusive, attributes); - - synchronized (_queueAdapters) - { - return _queueAdapters.get(queue); - } - - } - catch(QueueExistsException qe) - { - throw new IllegalArgumentException("Queue with name "+name+" already exists"); - } - catch(AMQException e) - { - throw new IllegalArgumentException(e); - } - - } - - public String getName() - { - return (String)getAttribute(NAME); - } - - public String setName(final String currentName, final String desiredName) - throws IllegalStateException, AccessControlException - { - throw new IllegalStateException(); - } - - - public String getType() - { - return (String)getAttribute(TYPE); - } - - public String setType(final String currentType, final String desiredType) - throws IllegalStateException, AccessControlException - { - throw new IllegalStateException(); - } - - - @Override - public State getActualState() - { - if (_virtualHost == null) - { - State state = (State)super.getAttribute(STATE); - if (state == null) - { - return State.INITIALISING; - } - return state; - } - else - { - org.apache.qpid.server.virtualhost.State implementationState = _virtualHost.getState(); - switch(implementationState) - { - case INITIALISING: - return State.INITIALISING; - case ACTIVE: - return State.ACTIVE; - case PASSIVE: - return State.REPLICA; - case STOPPED: - return State.STOPPED; - case ERRORED: - return State.ERRORED; - default: - throw new IllegalStateException("Unsupported state:" + implementationState); - } - } - } - - public boolean isDurable() - { - return true; - } - - public void setDurable(final boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; - } - - public LifetimePolicy setLifetimePolicy(final LifetimePolicy expected, final LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - public long getTimeToLive() - { - return 0; - } - - public long setTimeToLive(final long expected, final long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - public Statistics getStatistics() - { - return _statistics; - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - if(clazz == Exchange.class) - { - return (Collection<C>) getExchanges(); - } - else if(clazz == Queue.class) - { - return (Collection<C>) getQueues(); - } - else if(clazz == Connection.class) - { - return (Collection<C>) getConnections(); - } - else if(clazz == VirtualHostAlias.class) - { - return (Collection<C>) getAliases(); - } - else - { - return Collections.emptySet(); - } - } - - @Override - public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - if(childClass == Exchange.class) - { - createExchange(attributes); - - // return null to avoid double notification of VirtualHostMBean - // as we already notify it in the exchangeRegistered - return null; - } - else if(childClass == Queue.class) - { - createQueue(attributes); - - // return null to avoid double notification of VirtualHostMBean - // as we already notify it in the queueRegistered - return null; - } - else if(childClass == VirtualHostAlias.class) - { - throw new UnsupportedOperationException(); - } - else if(childClass == Connection.class) - { - throw new UnsupportedOperationException(); - } - throw new IllegalArgumentException("Cannot create a child of class " + childClass.getSimpleName()); - } - - public void exchangeRegistered(org.apache.qpid.server.exchange.Exchange exchange) - { - ExchangeAdapter adapter = null; - synchronized (_exchangeAdapters) - { - if(!_exchangeAdapters.containsKey(exchange)) - { - adapter = new ExchangeAdapter(this, exchange); - _exchangeAdapters.put(exchange, adapter); - - } - - } - if(adapter != null) - { - childAdded(adapter); - } - - } - - - public void exchangeUnregistered(org.apache.qpid.server.exchange.Exchange exchange) - { - ExchangeAdapter adapter; - synchronized (_exchangeAdapters) - { - adapter = _exchangeAdapters.remove(exchange); - - } - - if(adapter != null) - { - childRemoved(adapter); - } - } - - public void queueRegistered(AMQQueue queue) - { - QueueAdapter adapter = null; - synchronized (_queueAdapters) - { - if(!_queueAdapters.containsKey(queue)) - { - adapter = new QueueAdapter(this, queue); - _queueAdapters.put(queue, adapter); - - } - - } - if(adapter != null) - { - childAdded(adapter); - } - - } - - public void queueUnregistered(AMQQueue queue) - { - - QueueAdapter adapter; - synchronized (_queueAdapters) - { - adapter = _queueAdapters.remove(queue); - - } - - if(adapter != null) - { - childRemoved(adapter); - } - } - - public void connectionRegistered(AMQConnectionModel connection) - { - ConnectionAdapter adapter = null; - synchronized (_connectionAdapters) - { - if(!_connectionAdapters.containsKey(connection)) - { - adapter = new ConnectionAdapter(connection, getTaskExecutor()); - _connectionAdapters.put(connection, adapter); - - } - - } - if(adapter != null) - { - childAdded(adapter); - } - } - - public void connectionUnregistered(AMQConnectionModel connection) - { - - ConnectionAdapter adapter; - synchronized (_connectionAdapters) - { - adapter = _connectionAdapters.remove(connection); - - } - - if(adapter != null) - { - // Call getSessions() first to ensure that any SessionAdapter children are cleanly removed and any - // corresponding ConfigurationChangeListener childRemoved() callback is called for child SessionAdapters. - adapter.getSessions(); - - childRemoved(adapter); - } - } - - QueueAdapter getQueueAdapter(AMQQueue queue) - { - synchronized (_queueAdapters) - { - return _queueAdapters.get(queue); - } - } - - public Collection<String> getExchangeTypes() - { - Collection<ExchangeType<? extends org.apache.qpid.server.exchange.Exchange>> types = - _virtualHost.getExchangeTypes(); - - Collection<String> exchangeTypes = new ArrayList<String>(); - - for(ExchangeType<? extends org.apache.qpid.server.exchange.Exchange> type : types) - { - exchangeTypes.add(type.getType()); - } - return Collections.unmodifiableCollection(exchangeTypes); - } - - public void executeTransaction(TransactionalOperation op) - { - MessageStore store = _virtualHost.getMessageStore(); - final LocalTransaction txn = new LocalTransaction(store); - - op.withinTransaction(new Transaction() - { - public void dequeue(final QueueEntry entry) - { - if(entry.acquire()) - { - txn.dequeue(entry.getQueue(), entry.getMessage(), new ServerTransaction.Action() - { - public void postCommit() - { - entry.discard(); - } - - public void onRollback() - { - } - }); - } - } - - public void copy(QueueEntry entry, Queue queue) - { - final ServerMessage message = entry.getMessage(); - final AMQQueue toQueue = ((QueueAdapter)queue).getAMQQueue(); - - txn.enqueue(toQueue, message, new ServerTransaction.Action() - { - public void postCommit() - { - try - { - toQueue.enqueue(message); - } - catch(AMQException e) - { - throw new RuntimeException(e); - } - } - - public void onRollback() - { - } - }); - - } - - public void move(final QueueEntry entry, Queue queue) - { - final ServerMessage message = entry.getMessage(); - final AMQQueue toQueue = ((QueueAdapter)queue).getAMQQueue(); - if(entry.acquire()) - { - txn.enqueue(toQueue, message, - new ServerTransaction.Action() - { - - public void postCommit() - { - try - { - toQueue.enqueue(message); - } - catch (AMQException e) - { - throw new RuntimeException(e); - } - } - - public void onRollback() - { - entry.release(); - } - }); - txn.dequeue(entry.getQueue(), message, - new ServerTransaction.Action() - { - - public void postCommit() - { - entry.discard(); - } - - public void onRollback() - { - - } - }); - } - } - - }); - txn.commit(); - } - - org.apache.qpid.server.virtualhost.VirtualHost getVirtualHost() - { - return _virtualHost; - } - - @Override - public Object getAttribute(String name) - { - if(ID.equals(name)) - { - return getId(); - } - else if(STATE.equals(name)) - { - return getActualState(); - } - else if(DURABLE.equals(name)) - { - return isDurable(); - } - else if(LIFETIME_POLICY.equals(name)) - { - return LifetimePolicy.PERMANENT; - } - else if(TIME_TO_LIVE.equals(name)) - { - // TODO - } - else if(CREATED.equals(name)) - { - // TODO - } - else if(UPDATED.equals(name)) - { - // TODO - } - else if (_virtualHost != null) - { - return getAttributeFromVirtualHostImplementation(name); - } - return super.getAttribute(name); - } - - private Object getAttributeFromVirtualHostImplementation(String name) - { - if(SUPPORTED_EXCHANGE_TYPES.equals(name)) - { - List<String> types = new ArrayList<String>(); - for(@SuppressWarnings("rawtypes") ExchangeType type : _virtualHost.getExchangeTypes()) - { - types.add(type.getType()); - } - return Collections.unmodifiableCollection(types); - } - else if(SUPPORTED_QUEUE_TYPES.equals(name)) - { - // TODO - } - else if(QUEUE_DEAD_LETTER_QUEUE_ENABLED.equals(name)) - { - return _virtualHost.getConfiguration().isDeadLetterQueueEnabled(); - } - else if(HOUSEKEEPING_CHECK_PERIOD.equals(name)) - { - return _virtualHost.getConfiguration().getHousekeepingCheckPeriod(); - } - else if(QUEUE_MAXIMUM_DELIVERY_ATTEMPTS.equals(name)) - { - return _virtualHost.getConfiguration().getMaxDeliveryCount(); - } - else if(QUEUE_FLOW_CONTROL_SIZE_BYTES.equals(name)) - { - return _virtualHost.getConfiguration().getCapacity(); - } - else if(QUEUE_FLOW_RESUME_SIZE_BYTES.equals(name)) - { - return _virtualHost.getConfiguration().getFlowResumeCapacity(); - } - else if(STORE_TYPE.equals(name)) - { - return _virtualHost.getMessageStore().getStoreType(); - } - else if(STORE_PATH.equals(name)) - { - return _virtualHost.getMessageStore().getStoreLocation(); - } - else if(STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE.equals(name)) - { - return _virtualHost.getConfiguration().getTransactionTimeoutIdleClose(); - } - else if(STORE_TRANSACTION_IDLE_TIMEOUT_WARN.equals(name)) - { - return _virtualHost.getConfiguration().getTransactionTimeoutIdleWarn(); - } - else if(STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE.equals(name)) - { - return _virtualHost.getConfiguration().getTransactionTimeoutOpenClose(); - } - else if(STORE_TRANSACTION_OPEN_TIMEOUT_WARN.equals(name)) - { - return _virtualHost.getConfiguration().getTransactionTimeoutOpenWarn(); - } - else if(QUEUE_ALERT_REPEAT_GAP.equals(name)) - { - return _virtualHost.getConfiguration().getMinimumAlertRepeatGap(); - } - else if(QUEUE_ALERT_THRESHOLD_MESSAGE_AGE.equals(name)) - { - return _virtualHost.getConfiguration().getMaximumMessageAge(); - } - else if(QUEUE_ALERT_THRESHOLD_MESSAGE_SIZE.equals(name)) - { - return _virtualHost.getConfiguration().getMaximumMessageSize(); - } - else if(QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_BYTES.equals(name)) - { - return _virtualHost.getConfiguration().getMaximumQueueDepth(); - } - else if(QUEUE_ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES.equals(name)) - { - return _virtualHost.getConfiguration().getMaximumMessageCount(); - } - return super.getAttribute(name); - } - - @Override - public Collection<String> getAttributeNames() - { - return AVAILABLE_ATTRIBUTES; - } - - private void checkVHostStateIsActive() - { - if (!org.apache.qpid.server.virtualhost.State.ACTIVE.equals(_virtualHost.getState())) - { - throw new IllegalStateException("The virtual hosts state of " + _virtualHost.getState() - + " does not permit this operation."); - } - } - - - private static class VirtualHostStatisticsAdapter extends StatisticsAdapter - { - private final org.apache.qpid.server.virtualhost.VirtualHost _vhost; - - private static final Collection<String> VHOST_STATS = Arrays.asList( - VirtualHost.QUEUE_COUNT, - VirtualHost.EXCHANGE_COUNT, - VirtualHost.CONNECTION_COUNT); - - public VirtualHostStatisticsAdapter(org.apache.qpid.server.virtualhost.VirtualHost virtualHost) - { - super(virtualHost); - _vhost = virtualHost; - } - - @Override - public Collection<String> getStatisticNames() - { - Set<String> stats = new HashSet<String>(super.getStatisticNames()); - stats.addAll(VHOST_STATS); - return stats; - } - - @Override - public Object getStatistic(String name) - { - if(VirtualHost.QUEUE_COUNT.equals(name)) - { - return _vhost.getQueues().size(); - } - else if(VirtualHost.EXCHANGE_COUNT.equals(name)) - { - return _vhost.getExchanges().size(); - } - else if(VirtualHost.CONNECTION_COUNT.equals(name)) - { - return _vhost.getConnectionRegistry().getConnections().size(); - } - else - { - return super.getStatistic(name); - } - } - } - - - @Override - protected boolean setState(State currentState, State desiredState) - { - if (desiredState == State.ACTIVE) - { - try - { - activate(); - } - catch(RuntimeException e) - { - changeAttribute(STATE, State.INITIALISING, State.ERRORED); - if (_broker.isManagementMode()) - { - LOGGER.warn("Failed to activate virtual host: " + getName(), e); - } - else - { - throw e; - } - } - return true; - } - else if (desiredState == State.STOPPED) - { - if (_virtualHost != null) - { - try - { - _virtualHost.close(); - } - finally - { - _broker.getVirtualHostRegistry().unregisterVirtualHost(_virtualHost); - } - } - return true; - } - else if (desiredState == State.DELETED) - { - String hostName = getName(); - - if (hostName.equals(_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST))) - { - throw new IntegrityViolationException("Cannot delete default virtual host '" + hostName + "'"); - } - if (_virtualHost != null) - { - if (_virtualHost.getState() == org.apache.qpid.server.virtualhost.State.ACTIVE) - { - setDesiredState(currentState, State.STOPPED); - } - - MessageStore ms = _virtualHost.getMessageStore(); - if (ms != null) - { - try - { - ms.onDelete(); - } - catch(Exception e) - { - LOGGER.warn("Exception occured on store deletion", e); - } - } - - _virtualHost = null; - } - setAttribute(VirtualHost.STATE, getActualState(), State.DELETED); - return true; - } - return false; - } - - private void activate() - { - VirtualHostRegistry virtualHostRegistry = _broker.getVirtualHostRegistry(); - String virtualHostName = getName(); - try - { - VirtualHostConfiguration configuration = createVirtualHostConfiguration(virtualHostName); - String type = configuration.getType(); - final VirtualHostFactory factory = VirtualHostFactory.FACTORIES.get(type); - if(factory == null) - { - throw new IllegalArgumentException("Unknown virtual host type: " + type); - } - else - { - _virtualHost = factory.createVirtualHost(_broker.getVirtualHostRegistry(), - _brokerStatisticsGatherer, - _broker.getSecurityManager(), - configuration, - this); - } - } - catch (Exception e) - { - throw new RuntimeException("Failed to create virtual host " + virtualHostName, e); - } - - virtualHostRegistry.registerVirtualHost(_virtualHost); - - _statistics = new VirtualHostStatisticsAdapter(_virtualHost); - _virtualHost.addVirtualHostListener(this); - populateQueues(); - populateExchanges(); - - synchronized(_aliases) - { - for(Port port :_broker.getPorts()) - { - if (Protocol.hasAmqpProtocol(port.getProtocols())) - { - _aliases.add(new VirtualHostAliasAdapter(this, port)); - } - } - } - } - - private VirtualHostConfiguration createVirtualHostConfiguration(String virtualHostName) throws ConfigurationException - { - VirtualHostConfiguration configuration; - String configurationFile = (String)getAttribute(CONFIG_PATH); - if (configurationFile == null) - { - final MyConfiguration basicConfiguration = new MyConfiguration(); - PropertiesConfiguration config = new PropertiesConfiguration(); - final String type = (String) getAttribute(TYPE); - config.addProperty("type", type); - VirtualHostFactory factory = VirtualHostFactory.FACTORIES.get(type); - if(factory != null) - { - for(Map.Entry<String,Object> entry : factory.createVirtualHostConfiguration(this).entrySet()) - { - config.addProperty(entry.getKey(), entry.getValue()); - } - } - basicConfiguration.addConfiguration(config); - - CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); - compositeConfiguration.addConfiguration(new SystemConfiguration()); - compositeConfiguration.addConfiguration(basicConfiguration); - configuration = new VirtualHostConfiguration(virtualHostName, compositeConfiguration , _broker); - } - else - { - if (!new File(configurationFile).exists()) - { - throw new IllegalConfigurationException("Configuration file '" + configurationFile + "' does not exist"); - } - configuration = new VirtualHostConfiguration(virtualHostName, new File(configurationFile) , _broker); - String type = configuration.getType(); - changeAttribute(TYPE,null,type); - VirtualHostFactory factory = VirtualHostFactory.FACTORIES.get(type); - if(factory != null) - { - for(Map.Entry<String,Object> entry : factory.convertVirtualHostConfiguration(configuration.getConfig()).entrySet()) - { - changeAttribute(entry.getKey(), getAttribute(entry.getKey()), entry.getValue()); - } - } - - } - return configuration; - } - - @Override - public SecurityManager getSecurityManager() - { - return _virtualHost.getSecurityManager(); - } - - @Override - public MessageStore getMessageStore() - { - return _virtualHost.getMessageStore(); - } - - @Override - protected void changeAttributes(Map<String, Object> attributes) - { - throw new UnsupportedOperationException("Changing attributes on virtualhosts is not supported."); - } - - @Override - protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException - { - if(desiredState == State.DELETED) - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), VirtualHost.class, Operation.DELETE)) - { - throw new AccessControlException("Deletion of virtual host is denied"); - } - } - } - - @Override - protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), VirtualHost.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of virtual host attributes is denied"); - } - } - - @Override - protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException - { - if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), VirtualHost.class, Operation.UPDATE)) - { - throw new AccessControlException("Setting of virtual host attributes is denied"); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java deleted file mode 100644 index 91b705b004..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.model.adapter; - -import java.util.Map; -import org.apache.qpid.server.model.AuthenticationMethod; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.Statistics; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.model.VirtualHostAlias; - -import java.security.AccessControlException; -import java.util.Collection; -import java.util.Collections; - -public class VirtualHostAliasAdapter extends AbstractAdapter implements VirtualHostAlias -{ - private VirtualHostAdapter _vhost; - private Port _port; - - public VirtualHostAliasAdapter(VirtualHostAdapter virtualHostAdapter, Port port) - { - super(UUIDGenerator.generateVhostAliasUUID(virtualHostAdapter.getName(), port.getName()), virtualHostAdapter.getTaskExecutor()); - _vhost = virtualHostAdapter; - _port = port; - } - - @Override - public Port getPort() - { - return _port; - } - - @Override - public VirtualHost getVirtualHost() - { - return _vhost; - } - - @Override - public Collection<AuthenticationMethod> getAuthenticationMethods() - { - return Collections.emptySet(); // TODO - Implement - } - - @Override - public String getName() - { - return _vhost.getName(); - } - - @Override - public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException - { - throw new IllegalStateException(); // TODO - Implement - } - - @Override - public State getActualState() - { - return State.ACTIVE; // TODO - Implement - } - - @Override - public boolean isDurable() - { - return true; // TODO - Implement - } - - @Override - public void setDurable(boolean durable) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); - } - - @Override - public LifetimePolicy getLifetimePolicy() - { - return LifetimePolicy.PERMANENT; // TODO - Implement - } - - @Override - public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); // TODO - Implement - } - - @Override - public long getTimeToLive() - { - return 0; // TODO - Implement - } - - @Override - public long setTimeToLive(long expected, long desired) - throws IllegalStateException, AccessControlException, IllegalArgumentException - { - throw new IllegalStateException(); // TODO - Implement - } - - @Override - public Statistics getStatistics() - { - return NoStatistics.getInstance(); - } - - @Override - public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) - { - return Collections.emptySet(); - } - - @Override - public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents) - { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean setState(State currentState, State desiredState) - { - // TODO: state is not supported at the moment - return false; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java deleted file mode 100644 index 0298789672..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.Collection; -import java.util.Map; - -import org.apache.qpid.server.model.AccessControlProvider; -import org.apache.qpid.server.security.AccessControl; - -public interface AccessControlFactory extends Pluggable -{ - public static final String ATTRIBUTE_TYPE = AccessControlProvider.TYPE; - - AccessControl createInstance(Map<String, Object> attributes); - - /** - * Returns the access control provider type - * @return authentication provider type - */ - String getType(); - - /** - * Get the names of attributes of the access control which can be passed into - * {@link #createInstance(Map)} to create the group manager - * - * @return the collection of attribute names - */ - Collection<String> getAttributeNames(); - - /** - * @return returns human readable descriptions for the attributes - */ - Map<String, String> getAttributeDescriptions(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java deleted file mode 100644 index e183370870..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.Collection; -import java.util.Map; - -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; - -public interface AuthenticationManagerFactory extends Pluggable -{ - public static final String ATTRIBUTE_TYPE = AuthenticationProvider.TYPE; - - /** - * Returns the authentication provider type - * @return authentication provider type - */ - String getType(); - - /** - * Creates authentication manager from the provided attributes - * - * @param attributes - * attributes to create authentication manager - * @return authentication manager instance - */ - AuthenticationManager createInstance(Map<String, Object> attributes); - - /** - * Get the names of attributes the authentication manager which can be passed into {@link #createInstance(Map)} to create the - * authentication manager - * - * @return the collection of attribute names - */ - Collection<String> getAttributeNames(); - - /** - * @return returns human readable descriptions for the attributes - */ - Map<String, String> getAttributeDescriptions(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ConfigurationStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ConfigurationStoreFactory.java deleted file mode 100644 index 382c742161..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ConfigurationStoreFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.Map; - -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.IllegalConfigurationException; - - -public interface ConfigurationStoreFactory extends Pluggable -{ - /** - * Returns the type of the store this factory can create - */ - public String getType(); - - /** - * Creates and opens the store from a given location using initial store if provided. - * <p> - * If location does not exist, or the overwrite option is specified, then a new store is created from the initial store if it is provided - * - * @param storeLocation store location - * @param initialStore initial store - * @param overwrite overwrite existing store with initial store - * @param configProperties a map of configuration properties the store can use to resolve configuration variables - * @throws IllegalConfigurationException if store cannot be opened in the given location - */ - public ConfigurationEntryStore createStore(String storeLocation, ConfigurationEntryStore initialStore, boolean overwrite, Map<String, String> configProperties); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/DurableConfigurationStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/DurableConfigurationStoreFactory.java deleted file mode 100644 index 94a029ced3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/DurableConfigurationStoreFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.Map; -import org.apache.commons.configuration.Configuration; -import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.store.MessageStore; - -public interface DurableConfigurationStoreFactory extends Pluggable -{ - String getType(); - - DurableConfigurationStore createDurableConfigurationStore(); - - void validateAttributes(Map<String, Object> attributes); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java deleted file mode 100644 index ab19fa196e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.UUID; - -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public interface ExchangeType<T extends Exchange> extends Pluggable -{ - public String getType(); - - public T newInstance(UUID id, VirtualHost host, String name, - boolean durable, boolean autoDelete) throws AMQException; - - public String getDefaultExchangeName(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java deleted file mode 100644 index 3d7a6323eb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.Collection; -import java.util.Map; - -import org.apache.qpid.server.model.GroupProvider; -import org.apache.qpid.server.security.group.GroupManager; - -public interface GroupManagerFactory extends Pluggable -{ - public static final String ATTRIBUTE_TYPE = GroupProvider.TYPE; - - GroupManager createInstance(Map<String, Object> attributes); - - /** - * Returns the authentication provider type - * @return authentication provider type - */ - String getType(); - - /** - * Get the names of attributes the group manager which can be passed into {@link #createInstance(Map)} to create the - * group manager - * - * @return the collection of attribute names - */ - Collection<String> getAttributeNames(); - - /** - * @return returns human readable descriptions for the attributes - */ - Map<String, String> getAttributeDescriptions(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/JDBCConnectionProviderFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/JDBCConnectionProviderFactory.java deleted file mode 100644 index 12fb9224bb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/JDBCConnectionProviderFactory.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import org.apache.commons.configuration.Configuration; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.store.jdbc.ConnectionProvider; - -public interface JDBCConnectionProviderFactory extends Pluggable -{ - String getType(); - - ConnectionProvider getConnectionProvider(String connectionUrl, VirtualHost virtualHost) - throws SQLException; - - static final class TYPES - { - private TYPES() - { - } - - public static Collection<String> get() - { - QpidServiceLoader<JDBCConnectionProviderFactory> qpidServiceLoader = new QpidServiceLoader<JDBCConnectionProviderFactory>(); - Iterable<JDBCConnectionProviderFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(JDBCConnectionProviderFactory.class); - List<String> names = new ArrayList<String>(); - for(JDBCConnectionProviderFactory factory : factories) - { - names.add(factory.getType()); - } - return Collections.unmodifiableCollection(names); - } - } - - - static final class FACTORIES - { - private FACTORIES() - { - } - - public static JDBCConnectionProviderFactory get(String type) - { - QpidServiceLoader<JDBCConnectionProviderFactory> qpidServiceLoader = new QpidServiceLoader<JDBCConnectionProviderFactory>(); - Iterable<JDBCConnectionProviderFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(JDBCConnectionProviderFactory.class); - for(JDBCConnectionProviderFactory factory : factories) - { - if(factory.getType().equals(type)) - { - return factory; - } - } - return null; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageConverter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageConverter.java deleted file mode 100644 index cf3860ba92..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageConverter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public interface MessageConverter<M extends ServerMessage, N extends ServerMessage> extends Pluggable -{ - Class<M> getInputClass(); - Class<N> getOutputClass(); - - N convert(M message, VirtualHost vhost); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageMetaDataType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageMetaDataType.java deleted file mode 100644 index ee89782307..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageMetaDataType.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.nio.ByteBuffer; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.store.StorableMessageMetaData; -import org.apache.qpid.server.store.StoredMessage; - -public interface MessageMetaDataType<M extends StorableMessageMetaData> extends Pluggable -{ - - public static interface Factory<M extends StorableMessageMetaData> - { - M createMetaData(ByteBuffer buf); - } - - public int ordinal(); - - public M createMetaData(ByteBuffer buf); - - public ServerMessage<M> createMessage(StoredMessage<M> msg); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageStoreFactory.java deleted file mode 100644 index 81404dcba8..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/MessageStoreFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.Map; -import org.apache.commons.configuration.Configuration; -import org.apache.qpid.server.store.MessageStore; - -public interface MessageStoreFactory extends Pluggable -{ - String getType(); - - MessageStore createMessageStore(); - - public Map<String, Object> convertStoreConfiguration(Configuration configuration); - - void validateAttributes(Map<String, Object> attributes); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/Pluggable.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/Pluggable.java deleted file mode 100644 index cc18e83f8e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/Pluggable.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apache.qpid.server.plugin;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -public interface Pluggable -{ - String getType(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java deleted file mode 100644 index 7f804781a5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.Plugin; - -public interface PluginFactory extends Pluggable -{ - static final String PLUGIN_TYPE = "pluginType"; - - Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java deleted file mode 100644 index 5a95b88591..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.apache.qpid.server.plugin; - -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.PreferencesProvider; - -public interface PreferencesProviderFactory extends Pluggable -{ - PreferencesProvider createInstance(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProvider); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ProtocolEngineCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ProtocolEngineCreator.java deleted file mode 100644 index 2fa9084b8b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ProtocolEngineCreator.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.qpid.server.plugin;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import org.apache.qpid.protocol.ServerProtocolEngine; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.protocol.AmqpProtocolVersion; -import org.apache.qpid.transport.network.NetworkConnection; - -public interface ProtocolEngineCreator extends Pluggable -{ - AmqpProtocolVersion getVersion(); - byte[] getHeaderIdentifier(); - ServerProtocolEngine newProtocolEngine(Broker broker, NetworkConnection network, Port port, Transport transport, long id); -} - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java deleted file mode 100644 index 148a306b27..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ServiceLoader; - -import org.apache.log4j.Logger; - -/** - * Simple facade over a {@link ServiceLoader} to instantiate all configured implementations of an interface. - */ -public class QpidServiceLoader<C extends Pluggable> -{ - private static final Logger _logger = Logger.getLogger(QpidServiceLoader.class); - - public Iterable<C> instancesOf(Class<C> clazz) - { - return instancesOf(clazz, false); - } - - /** - * @throws RuntimeException if at least one implementation is not found. - */ - public Iterable<C> atLeastOneInstanceOf(Class<C> clazz) - { - return instancesOf(clazz, true); - } - - private Iterable<C> instancesOf(Class<C> clazz, boolean atLeastOne) - { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - Iterator<C> serviceLoaderIterator = ServiceLoader.load(clazz, classLoader).iterator(); - - // create a new list so we can log the count - List<C> serviceImplementations = new ArrayList<C>(); - while(serviceLoaderIterator.hasNext()) - { - serviceImplementations.add(serviceLoaderIterator.next()); - } - - if(atLeastOne && serviceImplementations.isEmpty()) - { - throw new RuntimeException("At least one implementation of " + clazz + " expected"); - } - - if(_logger.isDebugEnabled()) - { - _logger.debug("Found " + serviceImplementations.size() + " implementations of " + clazz); - } - - return serviceImplementations; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/VirtualHostFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/VirtualHostFactory.java deleted file mode 100644 index 9549b70c83..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/VirtualHostFactory.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.plugin; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import org.apache.commons.configuration.Configuration; -import org.apache.qpid.server.configuration.VirtualHostConfiguration; -import org.apache.qpid.server.model.adapter.VirtualHostAdapter; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; - -public interface VirtualHostFactory extends Pluggable -{ - String getType(); - - VirtualHost createVirtualHost(VirtualHostRegistry virtualHostRegistry, - StatisticsGatherer brokerStatisticsGatherer, - SecurityManager parentSecurityManager, - VirtualHostConfiguration hostConfig, - org.apache.qpid.server.model.VirtualHost virtualHost) throws Exception; - - void validateAttributes(Map<String, Object> attributes); - - Map<String, Object> createVirtualHostConfiguration(VirtualHostAdapter virtualHostAdapter); - - Map<String,Object> convertVirtualHostConfiguration(Configuration configuration); - - static final class TYPES - { - private TYPES() - { - } - - public static Collection<String> get() - { - QpidServiceLoader<VirtualHostFactory> qpidServiceLoader = new QpidServiceLoader<VirtualHostFactory>(); - Iterable<VirtualHostFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(VirtualHostFactory.class); - List<String> names = new ArrayList<String>(); - for(VirtualHostFactory factory : factories) - { - names.add(factory.getType()); - } - return Collections.unmodifiableCollection(names); - } - } - - - static final class FACTORIES - { - private FACTORIES() - { - } - - public static VirtualHostFactory get(String type) - { - QpidServiceLoader<VirtualHostFactory> qpidServiceLoader = new QpidServiceLoader<VirtualHostFactory>(); - Iterable<VirtualHostFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(VirtualHostFactory.class); - for(VirtualHostFactory factory : factories) - { - if(factory.getType().equals(type)) - { - return factory; - } - } - return null; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQConnectionModel.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQConnectionModel.java deleted file mode 100644 index 19c5d03e0c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQConnectionModel.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.protocol; - -import org.apache.qpid.AMQException; -import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.stats.StatisticsGatherer; - -import java.util.List; -import java.util.UUID; - -public interface AMQConnectionModel extends StatisticsGatherer -{ - /** - * Close the underlying Connection - * - * @param cause - * @param message - * @throws org.apache.qpid.AMQException - */ - public void close(AMQConstant cause, String message) throws AMQException; - - public void block(); - - public void unblock(); - - /** - * Close the given requested Session - * - * @param session - * @param cause - * @param message - * @throws org.apache.qpid.AMQException - */ - public void closeSession(AMQSessionModel session, AMQConstant cause, String message) throws AMQException; - - public long getConnectionId(); - - /** - * Get a list of all sessions using this connection. - * - * @return a list of {@link AMQSessionModel}s - */ - public List<AMQSessionModel> getSessionModels(); - - /** - * Return a {@link LogSubject} for the connection. - */ - public LogSubject getLogSubject(); - - public String getUserName(); - - public boolean isSessionNameUnique(byte[] name); - - String getRemoteAddressString(); - - String getClientId(); - - String getClientVersion(); - - String getPrincipalAsString(); - - long getSessionCountLimit(); - - long getLastIoTime(); - - Port getPort(); - - Transport getTransport(); - - void stop(); - - boolean isStopped(); - - String getVirtualHostName(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java deleted file mode 100644 index a3833eebb9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.protocol; - -import java.util.UUID; -import java.util.concurrent.ConcurrentSkipListSet; - -import org.apache.qpid.AMQException; -import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.message.InboundMessage; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.SimpleAMQQueue; - -/** - * Session model interface. - * Extends {@link Comparable} to allow objects to be inserted into a {@link ConcurrentSkipListSet} - * when monitoring the blocking and blocking of queues/sessions in {@link SimpleAMQQueue}. - */ -public interface AMQSessionModel extends Comparable<AMQSessionModel> -{ - public UUID getId(); - - public AMQConnectionModel getConnectionModel(); - - public String getClientID(); - - public void close() throws AMQException; - - public void close(AMQConstant cause, String message) throws AMQException; - - public LogSubject getLogSubject(); - - /** - * This method is called from the housekeeping thread to check the status of - * transactions on this session and react appropriately. - * - * If a transaction is open for too long or idle for too long then a warning - * is logged or the connection is closed, depending on the configuration. An open - * transaction is one that has recent activity. The transaction age is counted - * from the time the transaction was started. An idle transaction is one that - * has had no activity, such as publishing or acknowledging messages. - * - * @param openWarn time in milliseconds before alerting on open transaction - * @param openClose time in milliseconds before closing connection with open transaction - * @param idleWarn time in milliseconds before alerting on idle transaction - * @param idleClose time in milliseconds before closing connection with idle transaction - */ - public void checkTransactionStatus(long openWarn, long openClose, long idleWarn, long idleClose) throws AMQException; - - void block(AMQQueue queue); - - void unblock(AMQQueue queue); - - void block(); - - void unblock(); - - boolean getBlocking(); - - boolean onSameConnection(InboundMessage inbound); - - int getUnacknowledgedMessageCount(); - - Long getTxnCount(); - Long getTxnStart(); - Long getTxnCommits(); - Long getTxnRejects(); - - int getChannelId(); - - int getConsumerCount(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AmqpProtocolVersion.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AmqpProtocolVersion.java deleted file mode 100644 index 0a71fe257a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AmqpProtocolVersion.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.protocol; - -public enum AmqpProtocolVersion { v0_8, v0_9, v0_9_1, v0_10, v1_0_0 } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/LinkModel.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/LinkModel.java deleted file mode 100644 index 16120a3523..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/LinkModel.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.protocol; - -public interface LinkModel -{ -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/LinkRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/LinkRegistry.java deleted file mode 100644 index 67d6e9f8d1..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/LinkRegistry.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.protocol; - -import java.util.HashMap; -import java.util.Map; - -public class LinkRegistry -{ - private final Map<String, LinkModel> _sendingLinks = new HashMap<String, LinkModel>(); - private final Map<String, LinkModel> _receivingLinks = new HashMap<String, LinkModel>(); - - public synchronized LinkModel getDurableSendingLink(String name) - { - return _sendingLinks.get(name); - } - - public synchronized boolean registerSendingLink(String name, LinkModel link) - { - if(_sendingLinks.containsKey(name)) - { - return false; - } - else - { - _sendingLinks.put(name, link); - return true; - } - } - - public synchronized boolean unregisterSendingLink(String name) - { - if(!_sendingLinks.containsKey(name)) - { - return false; - } - else - { - _sendingLinks.remove(name); - return true; - } - } - - public synchronized LinkModel getDurableReceivingLink(String name) - { - return _receivingLinks.get(name); - } - - public synchronized boolean registerReceivingLink(String name, LinkModel link) - { - if(_receivingLinks.containsKey(name)) - { - return false; - } - else - { - _receivingLinks.put(name, link); - return true; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MessageConverterRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MessageConverterRegistry.java deleted file mode 100644 index 81e5af179d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MessageConverterRegistry.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.protocol; - -import java.util.HashMap; -import java.util.Map; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.plugin.MessageConverter; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class MessageConverterRegistry -{ - private static Map<Class<? extends ServerMessage>, Map<Class<? extends ServerMessage>, MessageConverter>> _converters = - new HashMap<Class<? extends ServerMessage>, Map<Class<? extends ServerMessage>, MessageConverter>>(); - - static - { - - for(MessageConverter<? extends ServerMessage, ? extends ServerMessage> converter : (new QpidServiceLoader<MessageConverter>()).instancesOf(MessageConverter.class)) - { - Map<Class<? extends ServerMessage>, MessageConverter> map = _converters.get(converter.getInputClass()); - if(map == null) - { - map = new HashMap<Class<? extends ServerMessage>, MessageConverter>(); - _converters.put(converter.getInputClass(), map); - } - map.put(converter.getOutputClass(),converter); - } - } - - public static <M extends ServerMessage,N extends ServerMessage> MessageConverter<M, N> getConverter(Class<M> from, Class<N> to) - { - Map<Class<? extends ServerMessage>, MessageConverter> map = _converters.get(from); - if(map == null) - { - map = _converters.get(ServerMessage.class); - } - return map == null ? null : map.get(to); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java deleted file mode 100755 index 47b578c4ef..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java +++ /dev/null @@ -1,680 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.protocol; - - -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.security.Principal; -import java.util.Set; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.SSLPeerUnverifiedException; -import org.apache.log4j.Logger; -import org.apache.qpid.protocol.ServerProtocolEngine; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.ConnectionMessages; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.plugin.ProtocolEngineCreator; -import org.apache.qpid.transport.Sender; -import org.apache.qpid.transport.network.NetworkConnection; -import org.apache.qpid.transport.network.security.SSLStatus; -import org.apache.qpid.transport.network.security.ssl.SSLBufferingSender; -import org.apache.qpid.transport.network.security.ssl.SSLReceiver; - -public class MultiVersionProtocolEngine implements ServerProtocolEngine -{ - private static final Logger _logger = Logger.getLogger(MultiVersionProtocolEngine.class); - - private final long _id; - private final SSLContext _sslContext; - private final boolean _wantClientAuth; - private final boolean _needClientAuth; - private final Port _port; - private final Transport _transport; - private final ProtocolEngineCreator[] _creators; - - private Set<AmqpProtocolVersion> _supported; - private String _fqdn; - private final Broker _broker; - private NetworkConnection _network; - private Sender<ByteBuffer> _sender; - private final AmqpProtocolVersion _defaultSupportedReply; - - private volatile ServerProtocolEngine _delegate = new SelfDelegateProtocolEngine(); - - public MultiVersionProtocolEngine(final Broker broker, - SSLContext sslContext, boolean wantClientAuth, boolean needClientAuth, - final Set<AmqpProtocolVersion> supported, - final AmqpProtocolVersion defaultSupportedReply, - Port port, Transport transport, final long id, ProtocolEngineCreator[] creators) - { - if(defaultSupportedReply != null && !supported.contains(defaultSupportedReply)) - { - throw new IllegalArgumentException("The configured default reply (" + defaultSupportedReply - + ") to an unsupported protocol version initiation is itself not supported!"); - } - - _id = id; - _broker = broker; - _supported = supported; - _defaultSupportedReply = defaultSupportedReply; - _sslContext = sslContext; - _wantClientAuth = wantClientAuth; - _needClientAuth = needClientAuth; - _port = port; - _transport = transport; - _creators = creators; - } - - - public SocketAddress getRemoteAddress() - { - return _delegate.getRemoteAddress(); - } - - public SocketAddress getLocalAddress() - { - return _delegate.getLocalAddress(); - } - - public long getWrittenBytes() - { - return _delegate.getWrittenBytes(); - } - - public long getReadBytes() - { - return _delegate.getReadBytes(); - } - - public void closed() - { - _delegate.closed(); - } - - public void writerIdle() - { - _delegate.writerIdle(); - } - - public void readerIdle() - { - _delegate.readerIdle(); - } - - - public void received(ByteBuffer msg) - { - _delegate.received(msg); - } - - public void exception(Throwable t) - { - _delegate.exception(t); - } - - public long getConnectionId() - { - return _delegate.getConnectionId(); - } - - private static final int MINIMUM_REQUIRED_HEADER_BYTES = 8; - - public void setNetworkConnection(NetworkConnection networkConnection) - { - setNetworkConnection(networkConnection, networkConnection.getSender()); - } - - public void setNetworkConnection(NetworkConnection network, Sender<ByteBuffer> sender) - { - _network = network; - SocketAddress address = _network.getLocalAddress(); - if (address instanceof InetSocketAddress) - { - _fqdn = ((InetSocketAddress) address).getHostName(); - } - else - { - throw new IllegalArgumentException("Unsupported socket address class: " + address); - } - _sender = sender; - } - - @Override - public long getLastReadTime() - { - return _delegate.getLastReadTime(); - } - - @Override - public long getLastWriteTime() - { - return _delegate.getLastWriteTime(); - } - - - - private class ClosedDelegateProtocolEngine implements ServerProtocolEngine - { - public SocketAddress getRemoteAddress() - { - return _network.getRemoteAddress(); - } - - public SocketAddress getLocalAddress() - { - return _network.getLocalAddress(); - } - - public long getWrittenBytes() - { - return 0; - } - - public long getReadBytes() - { - return 0; - } - - public void received(ByteBuffer msg) - { - _logger.error("Error processing incoming data, could not negotiate a common protocol"); - } - - public void exception(Throwable t) - { - _logger.error("Error establishing session", t); - } - - public void closed() - { - - } - - public void writerIdle() - { - - } - - public void readerIdle() - { - - } - - public void setNetworkConnection(NetworkConnection network, Sender<ByteBuffer> sender) - { - - } - - @Override - public long getLastReadTime() - { - return 0; - } - - @Override - public long getLastWriteTime() - { - return 0; - } - - public long getConnectionId() - { - return _id; - } - } - - private class SelfDelegateProtocolEngine implements ServerProtocolEngine - { - private final ByteBuffer _header = ByteBuffer.allocate(MINIMUM_REQUIRED_HEADER_BYTES); - private long _lastReadTime; - - public SocketAddress getRemoteAddress() - { - return _network.getRemoteAddress(); - } - - public SocketAddress getLocalAddress() - { - return _network.getLocalAddress(); - } - - public long getWrittenBytes() - { - return 0; - } - - public long getReadBytes() - { - return 0; - } - - public void received(ByteBuffer msg) - { - - _lastReadTime = System.currentTimeMillis(); - ByteBuffer msgheader = msg.duplicate(); - if(_header.remaining() > msgheader.limit()) - { - msg.position(msg.limit()); - } - else - { - msgheader.limit(_header.remaining()); - msg.position(_header.remaining()); - } - - _header.put(msgheader); - - if(!_header.hasRemaining()) - { - _header.flip(); - byte[] headerBytes = new byte[MINIMUM_REQUIRED_HEADER_BYTES]; - _header.get(headerBytes); - - - ServerProtocolEngine newDelegate = null; - byte[] supportedReplyBytes = null; - byte[] defaultSupportedReplyBytes = null; - AmqpProtocolVersion supportedReplyVersion = null; - - //Check the supported versions for a header match, and if there is one save the - //delegate. Also save most recent supported version and associated reply header bytes - for(int i = 0; newDelegate == null && i < _creators.length; i++) - { - if(_supported.contains(_creators[i].getVersion())) - { - supportedReplyBytes = _creators[i].getHeaderIdentifier(); - supportedReplyVersion = _creators[i].getVersion(); - byte[] compareBytes = _creators[i].getHeaderIdentifier(); - boolean equal = true; - for(int j = 0; equal && j<compareBytes.length; j++) - { - equal = headerBytes[j] == compareBytes[j]; - } - if(equal) - { - newDelegate = _creators[i].newProtocolEngine(_broker, _network, _port, _transport, _id); - } - } - - //If there is a configured default reply to an unsupported version initiation, - //then save the associated reply header bytes when we encounter them - if(_defaultSupportedReply != null && _creators[i].getVersion() == _defaultSupportedReply) - { - defaultSupportedReplyBytes = _creators[i].getHeaderIdentifier(); - } - } - - if(newDelegate == null && looksLikeSSL(headerBytes)) - { - if(_sslContext != null) - { - newDelegate = new SslDelegateProtocolEngine(); - } - } - - // If no delegate is found then send back a supported protocol version id - if(newDelegate == null) - { - //if a default reply was specified use its reply header instead of the most recent supported version - if(_defaultSupportedReply != null && !(_defaultSupportedReply == supportedReplyVersion)) - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Default reply to unsupported protocol version was configured, changing reply from " - + supportedReplyVersion + " to " + _defaultSupportedReply); - } - - supportedReplyBytes = defaultSupportedReplyBytes; - supportedReplyVersion = _defaultSupportedReply; - } - if(_logger.isDebugEnabled()) - { - _logger.debug("Unsupported protocol version requested, replying with: " + supportedReplyVersion); - } - _sender.send(ByteBuffer.wrap(supportedReplyBytes)); - _sender.flush(); - - _delegate = new ClosedDelegateProtocolEngine(); - - _network.close(); - - } - else - { - _delegate = newDelegate; - - _header.flip(); - _delegate.received(_header); - if(msg.hasRemaining()) - { - _delegate.received(msg); - } - } - - } - - } - - public long getConnectionId() - { - return _id; - } - - public void exception(Throwable t) - { - _logger.error("Error establishing session", t); - } - - public void closed() - { - try - { - _delegate = new ClosedDelegateProtocolEngine(); - if(_logger.isDebugEnabled()) - { - _logger.debug("Connection from " + getRemoteAddress() + " was closed before any protocol version was established."); - } - } - catch(Exception e) - { - //ignore - } - finally - { - try - { - _network.close(); - } - catch(Exception e) - { - //ignore - } - } - } - - public void writerIdle() - { - - } - - public void readerIdle() - { - CurrentActor.get().message(ConnectionMessages.IDLE_CLOSE()); - _network.close(); - } - - public void setNetworkConnection(NetworkConnection network, Sender<ByteBuffer> sender) - { - - } - - @Override - public long getLastReadTime() - { - return _lastReadTime; - } - - @Override - public long getLastWriteTime() - { - return 0; - } - } - - private class SslDelegateProtocolEngine implements ServerProtocolEngine - { - private final MultiVersionProtocolEngine _decryptEngine; - private final SSLEngine _engine; - private final SSLReceiver _sslReceiver; - private final SSLBufferingSender _sslSender; - private long _lastReadTime; - - private SslDelegateProtocolEngine() - { - - _decryptEngine = new MultiVersionProtocolEngine(_broker, null, false, false, _supported, - _defaultSupportedReply, _port, Transport.SSL, _id, _creators); - - _engine = _sslContext.createSSLEngine(); - _engine.setUseClientMode(false); - - if(_needClientAuth) - { - _engine.setNeedClientAuth(_needClientAuth); - } - else if(_wantClientAuth) - { - _engine.setWantClientAuth(_wantClientAuth); - } - - SSLStatus sslStatus = new SSLStatus(); - _sslReceiver = new SSLReceiver(_engine,_decryptEngine,sslStatus); - _sslSender = new SSLBufferingSender(_engine,_sender,sslStatus); - _decryptEngine.setNetworkConnection(new SSLNetworkConnection(_engine,_network, _sslSender)); - } - - @Override - public void received(ByteBuffer msg) - { - _lastReadTime = System.currentTimeMillis(); - _sslReceiver.received(msg); - _sslSender.send(); - _sslSender.flush(); - } - - @Override - public void setNetworkConnection(NetworkConnection network, Sender<ByteBuffer> sender) - { - //TODO - Implement - } - - @Override - public SocketAddress getRemoteAddress() - { - return _decryptEngine.getRemoteAddress(); - } - - @Override - public SocketAddress getLocalAddress() - { - return _decryptEngine.getLocalAddress(); - } - - @Override - public long getWrittenBytes() - { - return _decryptEngine.getWrittenBytes(); - } - - @Override - public long getReadBytes() - { - return _decryptEngine.getReadBytes(); - } - - @Override - public void closed() - { - _decryptEngine.closed(); - } - - @Override - public void writerIdle() - { - _decryptEngine.writerIdle(); - } - - @Override - public void readerIdle() - { - _decryptEngine.readerIdle(); - } - - @Override - public void exception(Throwable t) - { - _decryptEngine.exception(t); - } - - @Override - public long getConnectionId() - { - return _decryptEngine.getConnectionId(); - } - - @Override - public long getLastReadTime() - { - return _lastReadTime; - } - - @Override - public long getLastWriteTime() - { - return _decryptEngine.getLastWriteTime(); - } - } - - private boolean looksLikeSSL(byte[] headerBytes) - { - return looksLikeSSLv3ClientHello(headerBytes) || looksLikeSSLv2ClientHello(headerBytes); - } - - private boolean looksLikeSSLv3ClientHello(byte[] headerBytes) - { - return headerBytes[0] == 22 && // SSL Handshake - (headerBytes[1] == 3 && // SSL 3.0 / TLS 1.x - (headerBytes[2] == 0 || // SSL 3.0 - headerBytes[2] == 1 || // TLS 1.0 - headerBytes[2] == 2 || // TLS 1.1 - headerBytes[2] == 3)) && // TLS1.2 - (headerBytes[5] == 1); // client_hello - } - - private boolean looksLikeSSLv2ClientHello(byte[] headerBytes) - { - return headerBytes[0] == -128 && - headerBytes[3] == 3 && // SSL 3.0 / TLS 1.x - (headerBytes[4] == 0 || // SSL 3.0 - headerBytes[4] == 1 || // TLS 1.0 - headerBytes[4] == 2 || // TLS 1.1 - headerBytes[4] == 3); - } - - - private static class SSLNetworkConnection implements NetworkConnection - { - private final NetworkConnection _network; - private final SSLBufferingSender _sslSender; - private final SSLEngine _engine; - - public SSLNetworkConnection(SSLEngine engine, NetworkConnection network, - SSLBufferingSender sslSender) - { - _engine = engine; - _network = network; - _sslSender = sslSender; - - } - - @Override - public Sender<ByteBuffer> getSender() - { - return _sslSender; - } - - @Override - public void start() - { - _network.start(); - } - - @Override - public void close() - { - _sslSender.close(); - - _network.close(); - } - - @Override - public SocketAddress getRemoteAddress() - { - return _network.getRemoteAddress(); - } - - @Override - public SocketAddress getLocalAddress() - { - return _network.getLocalAddress(); - } - - @Override - public void setMaxWriteIdle(int sec) - { - _network.setMaxWriteIdle(sec); - } - - @Override - public void setMaxReadIdle(int sec) - { - _network.setMaxReadIdle(sec); - } - - @Override - public void setPeerPrincipal(Principal principal) - { - _network.setPeerPrincipal(principal); - } - - @Override - public Principal getPeerPrincipal() - { - try - { - return _engine.getSession().getPeerPrincipal(); - } - catch (SSLPeerUnverifiedException e) - { - return null; - } - } - - @Override - public int getMaxReadIdle() - { - return _network.getMaxReadIdle(); - } - - @Override - public int getMaxWriteIdle() - { - return _network.getMaxWriteIdle(); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java deleted file mode 100755 index 3ce9383ee0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java +++ /dev/null @@ -1,89 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.protocol; - -import java.util.ArrayList; -import java.util.List; -import javax.net.ssl.SSLContext; -import org.apache.qpid.protocol.ProtocolEngineFactory; -import org.apache.qpid.protocol.ServerProtocolEngine; -import org.apache.qpid.server.model.Broker; - -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.plugin.ProtocolEngineCreator; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class MultiVersionProtocolEngineFactory implements ProtocolEngineFactory -{ - private static final AtomicLong ID_GENERATOR = new AtomicLong(0); - - private final Broker _broker; - private final Set<AmqpProtocolVersion> _supported; - private final AmqpProtocolVersion _defaultSupportedReply; - private final SSLContext _sslContext; - private final boolean _wantClientAuth; - private final boolean _needClientAuth; - private final Port _port; - private final Transport _transport; - private final ProtocolEngineCreator[] _creators; - - public MultiVersionProtocolEngineFactory(Broker broker, - SSLContext sslContext, - boolean wantClientAuth, - boolean needClientAuth, - final Set<AmqpProtocolVersion> supportedVersions, - final AmqpProtocolVersion defaultSupportedReply, - Port port, - Transport transport) - { - if(defaultSupportedReply != null && !supportedVersions.contains(defaultSupportedReply)) - { - throw new IllegalArgumentException("The configured default reply (" + defaultSupportedReply - + ") to an unsupported protocol version initiation is itself not supported!"); - } - - _broker = broker; - _sslContext = sslContext; - _supported = supportedVersions; - _defaultSupportedReply = defaultSupportedReply; - List<ProtocolEngineCreator> creators = new ArrayList<ProtocolEngineCreator>(); - for(ProtocolEngineCreator c : new QpidServiceLoader<ProtocolEngineCreator>().instancesOf(ProtocolEngineCreator.class)) - { - creators.add(c); - } - _creators = creators.toArray(new ProtocolEngineCreator[creators.size()]); - _wantClientAuth = wantClientAuth; - _needClientAuth = needClientAuth; - _port = port; - _transport = transport; - } - - public ServerProtocolEngine newProtocolEngine() - { - return new MultiVersionProtocolEngine(_broker, _sslContext, _wantClientAuth, _needClientAuth, - _supported, _defaultSupportedReply, _port, _transport, - ID_GENERATOR.getAndIncrement(), - _creators); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQPriorityQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQPriorityQueue.java deleted file mode 100644 index 46c2a635b7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQPriorityQueue.java +++ /dev/null @@ -1,46 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.queue; - -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.Map; -import java.util.UUID; - -public class AMQPriorityQueue extends OutOfOrderQueue -{ - protected AMQPriorityQueue(UUID id, - final String name, - final boolean durable, - final String owner, - final boolean autoDelete, - boolean exclusive, - final VirtualHost virtualHost, - Map<String, Object> arguments, int priorities) - { - super(id, name, durable, owner, autoDelete, exclusive, virtualHost, new PriorityQueueList.Factory(priorities), arguments); - } - - public int getPriorities() - { - return ((PriorityQueueList) getEntries()).getPriorities(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java deleted file mode 100644 index ceebe4f965..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java +++ /dev/null @@ -1,331 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.configuration.QueueConfiguration; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.exchange.ExchangeReferrer; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.security.AuthorizationHolder; -import org.apache.qpid.server.store.TransactionLogResource; -import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public interface AMQQueue extends Comparable<AMQQueue>, ExchangeReferrer, TransactionLogResource, BaseQueue -{ - String getName(); - - public interface NotificationListener - { - void notifyClients(NotificationCheck notification, AMQQueue queue, String notificationMsg); - } - - boolean getDeleteOnNoConsumers(); - - void setDeleteOnNoConsumers(boolean b); - - void addBinding(Binding binding); - - void removeBinding(Binding binding); - - List<Binding> getBindings(); - - int getBindingCount(); - - LogSubject getLogSubject(); - - long getUnackedMessageBytes(); - - long getTotalDequeueCount(); - - long getTotalEnqueueCount(); - - public interface Context - { - QueueEntry getLastSeenEntry(); - } - - void setNoLocal(boolean b); - - boolean isAutoDelete(); - - String getOwner(); - AuthorizationHolder getAuthorizationHolder(); - void setAuthorizationHolder(AuthorizationHolder principalHolder); - - void setExclusiveOwningSession(AMQSessionModel owner); - AMQSessionModel getExclusiveOwningSession(); - - VirtualHost getVirtualHost(); - - void registerSubscription(final Subscription subscription, final boolean exclusive) throws AMQException; - - void unregisterSubscription(final Subscription subscription) throws AMQException; - - Collection<Subscription> getConsumers(); - - interface SubscriptionRegistrationListener - { - void subscriptionRegistered(AMQQueue queue, Subscription subscription); - void subscriptionUnregistered(AMQQueue queue, Subscription subscription); - } - - void addSubscriptionRegistrationListener(SubscriptionRegistrationListener listener); - void removeSubscriptionRegistrationListener(SubscriptionRegistrationListener listener); - - - int getConsumerCount(); - - int getActiveConsumerCount(); - - boolean hasExclusiveSubscriber(); - - boolean isUnused(); - - boolean isEmpty(); - - int getMessageCount(); - - int getUndeliveredMessageCount(); - - - long getQueueDepth(); - - long getReceivedMessageCount(); - - long getOldestMessageArrivalTime(); - - boolean isDeleted(); - - int delete() throws AMQException; - - void requeue(QueueEntry entry); - - void dequeue(QueueEntry entry, Subscription sub); - - void decrementUnackedMsgCount(QueueEntry queueEntry); - - boolean resend(final QueueEntry entry, final Subscription subscription) throws AMQException; - - void addQueueDeleteTask(final Task task); - void removeQueueDeleteTask(final Task task); - - - - List<QueueEntry> getMessagesOnTheQueue(); - - List<QueueEntry> getMessagesOnTheQueue(long fromMessageId, long toMessageId); - - List<Long> getMessagesOnTheQueue(int num); - - List<Long> getMessagesOnTheQueue(int num, int offest); - - QueueEntry getMessageOnTheQueue(long messageId); - - /** - * Returns a list of QueEntries from a given range of queue positions, eg messages 5 to 10 on the queue. - * - * The 'queue position' index starts from 1. Using 0 in 'from' will be ignored and continue from 1. - * Using 0 in the 'to' field will return an empty list regardless of the 'from' value. - * @param fromPosition - * @param toPosition - * @return - */ - public List<QueueEntry> getMessagesRangeOnTheQueue(final long fromPosition, final long toPosition); - - void visit(QueueEntryVisitor visitor); - - - long getMaximumMessageSize(); - - void setMaximumMessageSize(long value); - - - long getMaximumMessageCount(); - - void setMaximumMessageCount(long value); - - - long getMaximumQueueDepth(); - - void setMaximumQueueDepth(long value); - - - long getMaximumMessageAge(); - - void setMaximumMessageAge(final long maximumMessageAge); - - - long getMinimumAlertRepeatGap(); - - void setMinimumAlertRepeatGap(long value); - - - long getCapacity(); - - void setCapacity(long capacity); - - - long getFlowResumeCapacity(); - - void setFlowResumeCapacity(long flowResumeCapacity); - - boolean isOverfull(); - - void deleteMessageFromTop(); - - long clearQueue() throws AMQException; - - /** - * Checks the status of messages on the queue, purging expired ones, firing age related alerts etc. - * @throws AMQException - */ - void checkMessageStatus() throws AMQException; - - Set<NotificationCheck> getNotificationChecks(); - - void flushSubscription(final Subscription sub) throws AMQException; - - void deliverAsync(final Subscription sub); - - void deliverAsync(); - - void stop(); - - boolean isExclusive(); - - Exchange getAlternateExchange(); - - void setAlternateExchange(Exchange exchange); - - Collection<String> getAvailableAttributes(); - Object getAttribute(String attrName); - - void checkCapacity(AMQSessionModel channel); - - /** - * ExistingExclusiveSubscription signals a failure to create a subscription, because an exclusive subscription - * already exists. - * - * <p/><table id="crc"><caption>CRC Card</caption> - * <tr><th> Responsibilities <th> Collaborations - * <tr><td> Represent failure to create a subscription, because an exclusive subscription already exists. - * </table> - * - * @todo Not an AMQP exception as no status code. - * - * @todo Move to top level, used outside this class. - */ - static final class ExistingExclusiveSubscription extends AMQException - { - - public ExistingExclusiveSubscription() - { - super(""); - } - } - - /** - * ExistingSubscriptionPreventsExclusive signals a failure to create an exclusive subscription, as a subscription - * already exists. - * - * <p/><table id="crc"><caption>CRC Card</caption> - * <tr><th> Responsibilities <th> Collaborations - * <tr><td> Represent failure to create an exclusive subscription, as a subscription already exists. - * </table> - * - * @todo Not an AMQP exception as no status code. - * - * @todo Move to top level, used outside this class. - */ - static final class ExistingSubscriptionPreventsExclusive extends AMQException - { - public ExistingSubscriptionPreventsExclusive() - { - super(""); - } - } - - static interface Task - { - public void doTask(AMQQueue queue) throws AMQException; - } - - void configure(QueueConfiguration config); - - void setExclusive(boolean exclusive); - - /** - * Gets the maximum delivery count. If a message on this queue - * is delivered more than maximumDeliveryCount, the message will be - * routed to the {@link #getAlternateExchange()} (if set), or otherwise - * discarded. 0 indicates that maximum deliver count should not be enforced. - * - * @return maximum delivery count - */ - int getMaximumDeliveryCount(); - - /** - * Sets the maximum delivery count. - * - * @param maximumDeliveryCount maximum delivery count - */ - public void setMaximumDeliveryCount(final int maximumDeliveryCount); - - void setNotificationListener(NotificationListener listener); - - /** - * Sets the free text description of this queue. - * - * @param description - * - */ - void setDescription(String description); - - /** - * Gets the free text description of this queue. - */ - String getDescription(); - - long getPersistentByteDequeues(); - - long getPersistentMsgDequeues(); - - long getPersistentByteEnqueues(); - - long getPersistentMsgEnqueues(); - - long getTotalDequeueSize(); - - long getTotalEnqueueSize(); - - long getUnackedMessageCount(); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java deleted file mode 100644 index 029c7e4f86..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java +++ /dev/null @@ -1,542 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.configuration.QueueConfiguration; -import org.apache.qpid.server.exchange.DefaultExchangeFactory; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.store.DurableConfigurationStoreHelper; -import org.apache.qpid.server.virtualhost.ExchangeExistsException; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public class AMQQueueFactory implements QueueFactory -{ - public static final String QPID_DEFAULT_LVQ_KEY = "qpid.LVQ_key"; - - - public static final String DEFAULT_DLQ_NAME_SUFFIX = "_DLQ"; - public static final String DLQ_ROUTING_KEY = "dlq"; - private static final int MAX_LENGTH = 255; - - private final VirtualHost _virtualHost; - private final QueueRegistry _queueRegistry; - - public AMQQueueFactory(VirtualHost virtualHost, QueueRegistry queueRegistry) - { - _virtualHost = virtualHost; - _queueRegistry = queueRegistry; - } - - private abstract static class QueueProperty - { - - private final String _argumentName; - - - public QueueProperty(String argumentName) - { - _argumentName = argumentName; - } - - public String getArgumentName() - { - return _argumentName; - } - - - public abstract void setPropertyValue(AMQQueue queue, Object value); - - } - - private abstract static class QueueLongProperty extends QueueProperty - { - - public QueueLongProperty(String argumentName) - { - super(argumentName); - } - - public void setPropertyValue(AMQQueue queue, Object value) - { - if(value instanceof Number) - { - setPropertyValue(queue, ((Number)value).longValue()); - } - - } - - abstract void setPropertyValue(AMQQueue queue, long value); - - - } - - private abstract static class QueueIntegerProperty extends QueueProperty - { - public QueueIntegerProperty(String argumentName) - { - super(argumentName); - } - - public void setPropertyValue(AMQQueue queue, Object value) - { - if(value instanceof Number) - { - setPropertyValue(queue, ((Number)value).intValue()); - } - - } - abstract void setPropertyValue(AMQQueue queue, int value); - } - - private static final QueueProperty[] DECLAREABLE_PROPERTIES = { - new QueueLongProperty(Queue.ALERT_THRESHOLD_MESSAGE_AGE) - { - public void setPropertyValue(AMQQueue queue, long value) - { - queue.setMaximumMessageAge(value); - } - }, - new QueueLongProperty(Queue.ALERT_THRESHOLD_MESSAGE_SIZE) - { - public void setPropertyValue(AMQQueue queue, long value) - { - queue.setMaximumMessageSize(value); - } - }, - new QueueLongProperty(Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES) - { - public void setPropertyValue(AMQQueue queue, long value) - { - queue.setMaximumMessageCount(value); - } - }, - new QueueLongProperty(Queue.ALERT_THRESHOLD_QUEUE_DEPTH_BYTES) - { - public void setPropertyValue(AMQQueue queue, long value) - { - queue.setMaximumQueueDepth(value); - } - }, - new QueueLongProperty(Queue.ALERT_REPEAT_GAP) - { - public void setPropertyValue(AMQQueue queue, long value) - { - queue.setMinimumAlertRepeatGap(value); - } - }, - new QueueLongProperty(Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES) - { - public void setPropertyValue(AMQQueue queue, long value) - { - queue.setCapacity(value); - } - }, - new QueueLongProperty(Queue.QUEUE_FLOW_RESUME_SIZE_BYTES) - { - public void setPropertyValue(AMQQueue queue, long value) - { - queue.setFlowResumeCapacity(value); - } - }, - new QueueIntegerProperty(Queue.MAXIMUM_DELIVERY_ATTEMPTS) - { - public void setPropertyValue(AMQQueue queue, int value) - { - queue.setMaximumDeliveryCount(value); - } - } - }; - - @Override - public AMQQueue restoreQueue(UUID id, - String queueName, - String owner, - boolean autoDelete, - boolean exclusive, - boolean deleteOnNoConsumer, - Map<String, Object> arguments) throws AMQSecurityException, AMQException - { - return createOrRestoreQueue(id, queueName, true, owner, autoDelete, exclusive, deleteOnNoConsumer, arguments, false); - - } - - /** - * @param id the id to use. - * @param deleteOnNoConsumer - */ - @Override - public AMQQueue createQueue(UUID id, - String queueName, - boolean durable, - String owner, - boolean autoDelete, - boolean exclusive, - boolean deleteOnNoConsumer, - Map<String, Object> arguments) throws AMQSecurityException, AMQException - { - return createOrRestoreQueue(id, queueName, durable, owner, autoDelete, exclusive, deleteOnNoConsumer, arguments, true); - } - - private AMQQueue createOrRestoreQueue(UUID id, - String queueName, - boolean durable, - String owner, - boolean autoDelete, - boolean exclusive, - boolean deleteOnNoConsumer, - Map<String, Object> arguments, - boolean createInStore) throws AMQSecurityException, AMQException - { - if (id == null) - { - throw new IllegalArgumentException("Queue id must not be null"); - } - if (queueName == null) - { - throw new IllegalArgumentException("Queue name must not be null"); - } - - - QueueConfiguration queueConfiguration = _virtualHost.getConfiguration().getQueueConfiguration(queueName); - - boolean createDLQ = createDLQ(autoDelete, arguments, queueConfiguration); - if (createDLQ) - { - validateDLNames(queueName); - } - - int priorities = 1; - String conflationKey = null; - String sortingKey = null; - - if(arguments != null) - { - if(arguments.containsKey(Queue.LVQ_KEY)) - { - conflationKey = (String) arguments.get(Queue.LVQ_KEY); - if(conflationKey == null) - { - conflationKey = QPID_DEFAULT_LVQ_KEY; - } - } - else if(arguments.containsKey(Queue.PRIORITIES)) - { - Object prioritiesObj = arguments.get(Queue.PRIORITIES); - if(prioritiesObj instanceof Number) - { - priorities = ((Number)prioritiesObj).intValue(); - } - else if(prioritiesObj instanceof String) - { - try - { - priorities = Integer.parseInt(prioritiesObj.toString()); - } - catch (NumberFormatException e) - { - // TODO - should warn here of invalid format - } - } - else - { - // TODO - should warn here of invalid format - } - } - else if(arguments.containsKey(Queue.SORT_KEY)) - { - sortingKey = (String)arguments.get(Queue.SORT_KEY); - } - } - - AMQQueue q; - if(sortingKey != null) - { - q = new SortedQueue(id, queueName, durable, owner, autoDelete, exclusive, _virtualHost, arguments, sortingKey); - } - else if(conflationKey != null) - { - q = new ConflationQueue(id, queueName, durable, owner, autoDelete, exclusive, _virtualHost, arguments, conflationKey); - } - else if(priorities > 1) - { - q = new AMQPriorityQueue(id, queueName, durable, owner, autoDelete, exclusive, _virtualHost, arguments, priorities); - } - else - { - q = new SimpleAMQQueue(id, queueName, durable, owner, autoDelete, exclusive, _virtualHost, arguments); - } - - q.setDeleteOnNoConsumers(deleteOnNoConsumer); - - //Register the new queue - _queueRegistry.registerQueue(q); - - q.configure(_virtualHost.getConfiguration().getQueueConfiguration(queueName)); - - if(arguments != null) - { - for(QueueProperty p : DECLAREABLE_PROPERTIES) - { - if(arguments.containsKey(p.getArgumentName())) - { - p.setPropertyValue(q, arguments.get(p.getArgumentName())); - } - } - - if(arguments.get(Queue.NO_LOCAL) instanceof Boolean) - { - q.setNoLocal((Boolean)arguments.get(Queue.NO_LOCAL)); - } - - } - - if(createDLQ) - { - final String dlExchangeName = getDeadLetterExchangeName(queueName); - final String dlQueueName = getDeadLetterQueueName(queueName); - - Exchange dlExchange = null; - final UUID dlExchangeId = UUIDGenerator.generateExchangeUUID(dlExchangeName, _virtualHost.getName()); - - try - { - dlExchange = _virtualHost.createExchange(dlExchangeId, - dlExchangeName, - ExchangeDefaults.FANOUT_EXCHANGE_CLASS, - true, false, null); - } - catch(ExchangeExistsException e) - { - // We're ok if the exchange already exists - dlExchange = e.getExistingExchange(); - } - - AMQQueue dlQueue = null; - - synchronized(_queueRegistry) - { - dlQueue = _queueRegistry.getQueue(dlQueueName); - - if(dlQueue == null) - { - //set args to disable DLQ'ing/MDC from the DLQ itself, preventing loops etc - final Map<String, Object> args = new HashMap<String, Object>(); - args.put(Queue.CREATE_DLQ_ON_CREATION, false); - args.put(Queue.MAXIMUM_DELIVERY_ATTEMPTS, 0); - - dlQueue = _virtualHost.createQueue(UUIDGenerator.generateQueueUUID(dlQueueName, _virtualHost.getName()), dlQueueName, true, owner, false, exclusive, - false, args); - } - } - - //ensure the queue is bound to the exchange - if(!dlExchange.isBound(DLQ_ROUTING_KEY, dlQueue)) - { - //actual routing key used does not matter due to use of fanout exchange, - //but we will make the key 'dlq' as it can be logged at creation. - dlExchange.addBinding(DLQ_ROUTING_KEY, dlQueue, null); - } - q.setAlternateExchange(dlExchange); - } - else if(arguments != null && arguments.get(Queue.ALTERNATE_EXCHANGE) instanceof String) - { - - final String altExchangeAttr = (String) arguments.get(Queue.ALTERNATE_EXCHANGE); - Exchange altExchange; - try - { - altExchange = _virtualHost.getExchange(UUID.fromString(altExchangeAttr)); - } - catch(IllegalArgumentException e) - { - altExchange = _virtualHost.getExchange(altExchangeAttr); - } - q.setAlternateExchange(altExchange); - } - - if (createInStore && q.isDurable() && !q.isAutoDelete()) - { - DurableConfigurationStoreHelper.createQueue(_virtualHost.getDurableConfigurationStore(), q); - } - - return q; - } - - public AMQQueue createAMQQueueImpl(QueueConfiguration config) throws AMQException - { - String queueName = config.getName(); - - boolean durable = config.getDurable(); - boolean autodelete = config.getAutoDelete(); - boolean exclusive = config.getExclusive(); - String owner = config.getOwner(); - Map<String, Object> arguments = createQueueArgumentsFromConfig(config); - - // we need queues that are defined in config to have deterministic ids. - UUID id = UUIDGenerator.generateQueueUUID(queueName, _virtualHost.getName()); - - AMQQueue q = createQueue(id, queueName, durable, owner, autodelete, exclusive, false, arguments); - q.configure(config); - return q; - } - - /** - * Validates DLQ and DLE names - * <p> - * DLQ name and DLQ exchange name need to be validated in order to keep - * integrity in cases when queue name passes validation check but DLQ name - * or DL exchange name fails to pass it. Otherwise, we might have situations - * when queue is created but DL exchange or/and DLQ creation fail. - * <p> - * - * @param name - * queue name - * @throws IllegalArgumentException - * thrown if length of queue name or exchange name exceed 255 - */ - protected static void validateDLNames(String name) - { - // check if DLQ name and DLQ exchange name do not exceed 255 - String exchangeName = getDeadLetterExchangeName(name); - if (exchangeName.length() > MAX_LENGTH) - { - throw new IllegalArgumentException("DL exchange name '" + exchangeName - + "' length exceeds limit of " + MAX_LENGTH + " characters for queue " + name); - } - String queueName = getDeadLetterQueueName(name); - if (queueName.length() > MAX_LENGTH) - { - throw new IllegalArgumentException("DLQ queue name '" + queueName + "' length exceeds limit of " - + MAX_LENGTH + " characters for queue " + name); - } - } - - /** - * Checks if DLQ is enabled for the queue. - * - * @param autoDelete - * queue auto-delete flag - * @param arguments - * queue arguments - * @param qConfig - * queue configuration - * @return true if DLQ enabled - */ - protected static boolean createDLQ(boolean autoDelete, Map<String, Object> arguments, QueueConfiguration qConfig) - { - //feature is not to be enabled for temporary queues or when explicitly disabled by argument - if (!(autoDelete || (arguments != null && arguments.containsKey(Queue.ALTERNATE_EXCHANGE)))) - { - boolean dlqArgumentPresent = arguments != null - && arguments.containsKey(Queue.CREATE_DLQ_ON_CREATION); - if (dlqArgumentPresent || qConfig.isDeadLetterQueueEnabled()) - { - boolean dlqEnabled = true; - if (dlqArgumentPresent) - { - Object argument = arguments.get(Queue.CREATE_DLQ_ON_CREATION); - dlqEnabled = (argument instanceof Boolean && ((Boolean)argument).booleanValue()) - || (argument instanceof String && Boolean.parseBoolean(argument.toString())); - } - return dlqEnabled ; - } - } - return false; - } - - /** - * Generates a dead letter queue name for a given queue name - * - * @param name - * queue name - * @return DLQ name - */ - protected static String getDeadLetterQueueName(String name) - { - return name + System.getProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, DEFAULT_DLQ_NAME_SUFFIX); - } - - /** - * Generates a dead letter exchange name for a given queue name - * - * @param name - * queue name - * @return DL exchange name - */ - protected static String getDeadLetterExchangeName(String name) - { - return name + System.getProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX); - } - - private static Map<String, Object> createQueueArgumentsFromConfig(QueueConfiguration config) - { - Map<String,Object> arguments = new HashMap<String,Object>(); - - if(config.getArguments() != null && !config.getArguments().isEmpty()) - { - arguments.putAll(QueueArgumentsConverter.convertWireArgsToModel(new HashMap<String, Object>(config.getArguments()))); - } - - if(config.isLVQ() || config.getLVQKey() != null) - { - arguments.put(Queue.LVQ_KEY, config.getLVQKey() == null ? QPID_DEFAULT_LVQ_KEY : config.getLVQKey()); - } - else if (config.getPriority() || config.getPriorities() > 0) - { - arguments.put(Queue.PRIORITIES, config.getPriorities() < 0 ? 10 : config.getPriorities()); - } - else if (config.getQueueSortKey() != null && !"".equals(config.getQueueSortKey())) - { - arguments.put(Queue.SORT_KEY, config.getQueueSortKey()); - } - - if (!config.getAutoDelete() && config.isDeadLetterQueueEnabled()) - { - arguments.put(Queue.CREATE_DLQ_ON_CREATION, true); - } - - if (config.getDescription() != null && !"".equals(config.getDescription())) - { - arguments.put(Queue.DESCRIPTION, config.getDescription()); - } - - if (arguments.isEmpty()) - { - return Collections.emptyMap(); - } - else - { - return arguments; - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/BaseQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/BaseQueue.java deleted file mode 100644 index 6145570b0c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/BaseQueue.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.store.TransactionLogResource; - -public interface BaseQueue extends TransactionLogResource -{ - public static interface PostEnqueueAction - { - public void onEnqueue(QueueEntry entry); - } - - void enqueue(ServerMessage message) throws AMQException; - void enqueue(ServerMessage message, PostEnqueueAction action) throws AMQException; - void enqueue(ServerMessage message, boolean transactional, PostEnqueueAction action) throws AMQException; - - boolean isDurable(); - boolean isDeleted(); - - String getName(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ConflationQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ConflationQueue.java deleted file mode 100644 index c2813bb7a5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ConflationQueue.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.virtualhost.VirtualHost; - -public class ConflationQueue extends SimpleAMQQueue -{ - protected ConflationQueue(UUID id, - String name, - boolean durable, - String owner, - boolean autoDelete, - boolean exclusive, - VirtualHost virtualHost, - Map<String, Object> args, String conflationKey) - { - super(id, name, durable, owner, autoDelete, exclusive, virtualHost, new ConflationQueueList.Factory(conflationKey), args); - } - - public String getConflationKey() - { - return ((ConflationQueueList) getEntries()).getConflationKey(); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ConflationQueueList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ConflationQueueList.java deleted file mode 100644 index 53420ded9b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ConflationQueueList.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.txn.AutoCommitTransaction; -import org.apache.qpid.server.txn.ServerTransaction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicReference; - -public class ConflationQueueList extends SimpleQueueEntryList -{ - private static final Logger LOGGER = LoggerFactory.getLogger(ConflationQueueList.class); - - private final String _conflationKey; - private final ConcurrentHashMap<Object, AtomicReference<QueueEntry>> _latestValuesMap = - new ConcurrentHashMap<Object, AtomicReference<QueueEntry>>(); - - private final QueueEntry _deleteInProgress = new SimpleQueueEntryImpl(this); - private final QueueEntry _newerEntryAlreadyBeenAndGone = new SimpleQueueEntryImpl(this); - - public ConflationQueueList(AMQQueue queue, String conflationKey) - { - super(queue); - _conflationKey = conflationKey; - } - - public String getConflationKey() - { - return _conflationKey; - } - - @Override - protected ConflationQueueEntry createQueueEntry(ServerMessage message) - { - return new ConflationQueueEntry(this, message); - } - - /** - * Updates the list using super.add and also updates {@link #_latestValuesMap} and discards entries as necessary. - */ - @Override - public ConflationQueueEntry add(final ServerMessage message) - { - final ConflationQueueEntry addedEntry = (ConflationQueueEntry) (super.add(message)); - - final Object keyValue = message.getMessageHeader().getHeader(_conflationKey); - if (keyValue != null) - { - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("Adding entry " + addedEntry + " for message " + message.getMessageNumber() + " with conflation key " + keyValue); - } - - final AtomicReference<QueueEntry> referenceToEntry = new AtomicReference<QueueEntry>(addedEntry); - AtomicReference<QueueEntry> entryReferenceFromMap = null; - QueueEntry entryFromMap; - - // Iterate until we have got a valid atomic reference object and either the referent is newer than the current - // entry, or the current entry has replaced it in the reference. Note that the _deletedEntryPlaceholder is a special value - // indicating that the reference object is no longer valid (it is being removed from the map). - boolean keepTryingToUpdateEntryReference = true; - do - { - do - { - entryReferenceFromMap = getOrPutIfAbsent(keyValue, referenceToEntry); - - // entryFromMap can be either an older entry, a newer entry (added recently by another thread), or addedEntry (if it's for a new key value) - entryFromMap = entryReferenceFromMap.get(); - } - while(entryFromMap == _deleteInProgress); - - boolean entryFromMapIsOlder = entryFromMap != _newerEntryAlreadyBeenAndGone && entryFromMap.compareTo(addedEntry) < 0; - - keepTryingToUpdateEntryReference = entryFromMapIsOlder - && !entryReferenceFromMap.compareAndSet(entryFromMap, addedEntry); - } - while(keepTryingToUpdateEntryReference); - - if (entryFromMap == _newerEntryAlreadyBeenAndGone) - { - discardEntry(addedEntry); - } - else if (entryFromMap.compareTo(addedEntry) > 0) - { - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("New entry " + addedEntry.getEntryId() + " for message " + addedEntry.getMessage().getMessageNumber() + " being immediately discarded because a newer entry arrived. The newer entry is: " + entryFromMap + " for message " + entryFromMap.getMessage().getMessageNumber()); - } - discardEntry(addedEntry); - } - else if (entryFromMap.compareTo(addedEntry) < 0) - { - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("Entry " + addedEntry + " for message " + addedEntry.getMessage().getMessageNumber() + " replacing older entry " + entryFromMap + " for message " + entryFromMap.getMessage().getMessageNumber()); - } - discardEntry(entryFromMap); - } - - addedEntry.setLatestValueReference(entryReferenceFromMap); - } - - return addedEntry; - } - - /** - * Returns: - * - * <ul> - * <li>the existing entry reference if the value already exists in the map, or</li> - * <li>referenceToValue if none exists, or</li> - * <li>a reference to {@link #_newerEntryAlreadyBeenAndGone} if another thread concurrently - * adds and removes during execution of this method.</li> - * </ul> - */ - private AtomicReference<QueueEntry> getOrPutIfAbsent(final Object key, final AtomicReference<QueueEntry> referenceToAddedValue) - { - AtomicReference<QueueEntry> latestValueReference = _latestValuesMap.putIfAbsent(key, referenceToAddedValue); - - if(latestValueReference == null) - { - latestValueReference = _latestValuesMap.get(key); - if(latestValueReference == null) - { - return new AtomicReference<QueueEntry>(_newerEntryAlreadyBeenAndGone); - } - } - return latestValueReference; - } - - private void discardEntry(final QueueEntry entry) - { - if(entry.acquire()) - { - ServerTransaction txn = new AutoCommitTransaction(getQueue().getVirtualHost().getMessageStore()); - txn.dequeue(entry.getQueue(),entry.getMessage(), - new ServerTransaction.Action() - { - @Override - public void postCommit() - { - entry.discard(); - } - - @Override - public void onRollback() - { - - } - }); - } - } - - private final class ConflationQueueEntry extends SimpleQueueEntryImpl - { - - private AtomicReference<QueueEntry> _latestValueReference; - - public ConflationQueueEntry(SimpleQueueEntryList queueEntryList, ServerMessage message) - { - super(queueEntryList, message); - } - - @Override - public void release() - { - super.release(); - - discardIfReleasedEntryIsNoLongerLatest(); - } - - @Override - public boolean delete() - { - if(super.delete()) - { - if(_latestValueReference != null && _latestValueReference.compareAndSet(this, _deleteInProgress)) - { - Object key = getMessageHeader().getHeader(_conflationKey); - _latestValuesMap.remove(key,_latestValueReference); - } - return true; - } - else - { - return false; - } - } - - public void setLatestValueReference(final AtomicReference<QueueEntry> latestValueReference) - { - _latestValueReference = latestValueReference; - } - - private void discardIfReleasedEntryIsNoLongerLatest() - { - if(_latestValueReference != null) - { - if(_latestValueReference.get() != this) - { - discardEntry(this); - } - } - } - - } - - /** - * Exposed purposes of unit test only. - */ - Map<Object, AtomicReference<QueueEntry>> getLatestValuesMap() - { - return Collections.unmodifiableMap(_latestValuesMap); - } - - static class Factory implements QueueEntryListFactory - { - private final String _conflationKey; - - Factory(String conflationKey) - { - _conflationKey = conflationKey; - } - - public ConflationQueueList createQueueEntryList(AMQQueue queue) - { - return new ConflationQueueList(queue, _conflationKey); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/DefaultQueueRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/DefaultQueueRegistry.java deleted file mode 100644 index 7d091dbf73..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/DefaultQueueRegistry.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -public class DefaultQueueRegistry implements QueueRegistry -{ - private ConcurrentMap<String, AMQQueue> _queueMap = new ConcurrentHashMap<String, AMQQueue>(); - - private final VirtualHost _virtualHost; - private final Collection<RegistryChangeListener> _listeners = - new ArrayList<RegistryChangeListener>(); - - public DefaultQueueRegistry(VirtualHost virtualHost) - { - _virtualHost = virtualHost; - } - - public VirtualHost getVirtualHost() - { - return _virtualHost; - } - - public void registerQueue(AMQQueue queue) - { - _queueMap.put(queue.getName(), queue); - synchronized (_listeners) - { - for(RegistryChangeListener listener : _listeners) - { - listener.queueRegistered(queue); - } - } - } - - public void unregisterQueue(String name) - { - AMQQueue q = _queueMap.remove(name); - if(q != null) - { - synchronized (_listeners) - { - for(RegistryChangeListener listener : _listeners) - { - listener.queueUnregistered(q); - } - } - } - } - - - public Collection<AMQQueue> getQueues() - { - return _queueMap.values(); - } - - public AMQQueue getQueue(String queue) - { - return queue == null ? null : _queueMap.get(queue); - } - - public void addRegistryChangeListener(RegistryChangeListener listener) - { - synchronized(_listeners) - { - _listeners.add(listener); - } - } - - @Override - public void stopAllAndUnregisterMBeans() - { - for (final AMQQueue queue : getQueues()) - { - queue.stop(); - - //TODO: this is a bit of a hack, what if the listeners aren't aware - //that we are just unregistering the MBean because of HA, and aren't - //actually removing the queue as such. - synchronized (_listeners) - { - for(RegistryChangeListener listener : _listeners) - { - listener.queueUnregistered(queue); - } - } - } - _queueMap.clear(); - } - - @Override - public synchronized AMQQueue getQueue(UUID queueId) - { - Collection<AMQQueue> queues = _queueMap.values(); - for (AMQQueue queue : queues) - { - if (queue.getId().equals(queueId)) - { - return queue; - } - } - return null; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/Filterable.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/Filterable.java deleted file mode 100644 index 50d8f4166d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/Filterable.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.queue; - -import org.apache.qpid.server.message.AMQMessageHeader; - -public interface Filterable -{ - AMQMessageHeader getMessageHeader(); - - boolean isPersistent(); - - boolean isRedelivered(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/InboundMessageAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/InboundMessageAdapter.java deleted file mode 100755 index 2a78ee430c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/InboundMessageAdapter.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.message.AMQMessageHeader; -import org.apache.qpid.server.message.InboundMessage; - -public class InboundMessageAdapter implements InboundMessage -{ - - private QueueEntry _entry; - - InboundMessageAdapter() - { - } - - public InboundMessageAdapter(QueueEntry entry) - { - _entry = entry; - } - - public void setEntry(QueueEntry entry) - { - _entry = entry; - } - - public String getRoutingKey() - { - return _entry.getMessage().getRoutingKey(); - } - - public AMQMessageHeader getMessageHeader() - { - return _entry.getMessageHeader(); - } - - public boolean isPersistent() - { - return _entry.isPersistent(); - } - - public boolean isRedelivered() - { - return _entry.isRedelivered(); - } - - public long getSize() - { - return _entry.getSize(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/NotificationCheck.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/NotificationCheck.java deleted file mode 100644 index 566cdd0ea5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/NotificationCheck.java +++ /dev/null @@ -1,150 +0,0 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.qpid.server.queue;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.message.ServerMessage;
-
-public enum NotificationCheck
-{
-
- MESSAGE_COUNT_ALERT
- {
- public boolean notifyIfNecessary(ServerMessage<?> msg, AMQQueue queue, AMQQueue.NotificationListener listener)
- {
- int msgCount;
- final long maximumMessageCount = queue.getMaximumMessageCount();
- if (maximumMessageCount!= 0 && (msgCount = queue.getMessageCount()) >= maximumMessageCount)
- {
- String notificationMsg = msgCount + ": Maximum count on queue threshold ("+ maximumMessageCount +") breached.";
-
- logNotification(this, queue, notificationMsg);
- listener.notifyClients(this, queue, notificationMsg);
- return true;
- }
- return false;
- }
- },
- MESSAGE_SIZE_ALERT(true)
- {
- public boolean notifyIfNecessary(ServerMessage<?> msg, AMQQueue queue, AMQQueue.NotificationListener listener)
- {
- final long maximumMessageSize = queue.getMaximumMessageSize();
- if(maximumMessageSize != 0)
- {
- // Check for threshold message size
- long messageSize;
- messageSize = (msg == null) ? 0 : msg.getSize();
-
- if (messageSize >= maximumMessageSize)
- {
- String notificationMsg = messageSize + "b : Maximum message size threshold ("+ maximumMessageSize +") breached. [Message ID=" + msg.getMessageNumber() + "]";
-
- logNotification(this, queue, notificationMsg);
- listener.notifyClients(this, queue, notificationMsg);
- return true;
- }
- }
- return false;
- }
-
- },
- QUEUE_DEPTH_ALERT
- {
- public boolean notifyIfNecessary(ServerMessage<?> msg, AMQQueue queue, AMQQueue.NotificationListener listener)
- {
- // Check for threshold queue depth in bytes
- final long maximumQueueDepth = queue.getMaximumQueueDepth();
-
- if(maximumQueueDepth != 0)
- {
- final long queueDepth = queue.getQueueDepth();
-
- if (queueDepth >= maximumQueueDepth)
- {
- String notificationMsg = (queueDepth>>10) + "Kb : Maximum queue depth threshold ("+(maximumQueueDepth>>10)+"Kb) breached.";
-
- logNotification(this, queue, notificationMsg);
- listener.notifyClients(this, queue, notificationMsg);
- return true;
- }
- }
- return false;
- }
-
- },
- MESSAGE_AGE_ALERT
- {
- public boolean notifyIfNecessary(ServerMessage<?> msg, AMQQueue queue, AMQQueue.NotificationListener listener)
- {
-
- final long maxMessageAge = queue.getMaximumMessageAge();
- if(maxMessageAge != 0)
- {
- final long currentTime = System.currentTimeMillis();
- final long thresholdTime = currentTime - maxMessageAge;
- final long firstArrivalTime = queue.getOldestMessageArrivalTime();
-
- if(firstArrivalTime < thresholdTime)
- {
- long oldestAge = currentTime - firstArrivalTime;
- String notificationMsg = (oldestAge/1000) + "s : Maximum age on queue threshold ("+(maxMessageAge /1000)+"s) breached.";
-
- logNotification(this, queue, notificationMsg);
- listener.notifyClients(this, queue, notificationMsg);
-
- return true;
- }
- }
- return false;
-
- }
-
- }
- ;
-
- private static final Logger LOGGER = Logger.getLogger(NotificationCheck.class);
-
- private final boolean _messageSpecific;
-
- NotificationCheck()
- {
- this(false);
- }
-
- NotificationCheck(boolean messageSpecific)
- {
- _messageSpecific = messageSpecific;
- }
-
- public boolean isMessageSpecific()
- {
- return _messageSpecific;
- }
-
- public abstract boolean notifyIfNecessary(ServerMessage<?> msg, AMQQueue queue, AMQQueue.NotificationListener listener);
-
- //A bit of a hack, only for use until we do the logging listener
- private static void logNotification(NotificationCheck notification, AMQQueue queue, String notificationMsg)
- {
- LOGGER.info(notification.name() + " On Queue " + queue.getName() + " - " + notificationMsg);
- }
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/OutOfOrderQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/OutOfOrderQueue.java deleted file mode 100644 index daa5db393a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/OutOfOrderQueue.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.server.subscription.SubscriptionList; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.Map; -import java.util.UUID; - -public abstract class OutOfOrderQueue extends SimpleAMQQueue -{ - - protected OutOfOrderQueue(UUID id, String name, boolean durable, - String owner, boolean autoDelete, boolean exclusive, - VirtualHost virtualHost, QueueEntryListFactory entryListFactory, Map<String, Object> arguments) - { - super(id, name, durable, owner, autoDelete, exclusive, virtualHost, entryListFactory, arguments); - } - - @Override - protected void checkSubscriptionsNotAheadOfDelivery(final QueueEntry entry) - { - // check that all subscriptions are not in advance of the entry - SubscriptionList.SubscriptionNodeIterator subIter = getSubscriptionList().iterator(); - while(subIter.advance() && !entry.isAcquired()) - { - final Subscription subscription = subIter.getNode().getSubscription(); - if(!subscription.isClosed()) - { - QueueContext context = (QueueContext) subscription.getQueueContext(); - if(context != null) - { - QueueEntry released = context.getReleasedEntry(); - while(!entry.isAcquired() && (released == null || released.compareTo(entry) > 0)) - { - if(QueueContext._releasedUpdater.compareAndSet(context,released,entry)) - { - break; - } - else - { - released = context.getReleasedEntry(); - } - } - } - } - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java deleted file mode 100644 index 66315af9fb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java +++ /dev/null @@ -1,217 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.queue; - -import org.apache.qpid.server.message.ServerMessage; - -public class PriorityQueueList implements QueueEntryList<SimpleQueueEntryImpl> -{ - private final AMQQueue _queue; - private final PriorityQueueEntrySubList[] _priorityLists; - private final int _priorities; - private final int _priorityOffset; - - public PriorityQueueList(AMQQueue queue, int priorities) - { - _queue = queue; - _priorityLists = new PriorityQueueEntrySubList[priorities]; - _priorities = priorities; - _priorityOffset = 5-((priorities + 1)/2); - for(int i = 0; i < priorities; i++) - { - _priorityLists[i] = new PriorityQueueEntrySubList(queue, i); - } - } - - public int getPriorities() - { - return _priorities; - } - - public AMQQueue getQueue() - { - return _queue; - } - - public SimpleQueueEntryImpl add(ServerMessage message) - { - int index = message.getMessageHeader().getPriority() - _priorityOffset; - if(index >= _priorities) - { - index = _priorities-1; - } - else if(index < 0) - { - index = 0; - } - return _priorityLists[index].add(message); - - } - - public SimpleQueueEntryImpl next(SimpleQueueEntryImpl node) - { - SimpleQueueEntryImpl next = node.getNextValidEntry(); - - if(next == null) - { - final QueueEntryList<?> nodeEntryList = node.getQueueEntryList(); - int index; - for(index = _priorityLists.length-1; _priorityLists[index] != nodeEntryList; index--) {}; - - while(next == null && index != 0) - { - index--; - next = _priorityLists[index].getHead().getNextValidEntry(); - } - - } - return next; - } - - private final class PriorityQueueEntryListIterator implements QueueEntryIterator<SimpleQueueEntryImpl> - { - private final SimpleQueueEntryList.QueueEntryIteratorImpl[] _iterators = new SimpleQueueEntryList.QueueEntryIteratorImpl[ _priorityLists.length ]; - private SimpleQueueEntryImpl _lastNode; - - PriorityQueueEntryListIterator() - { - for(int i = 0; i < _priorityLists.length; i++) - { - _iterators[i] = _priorityLists[i].iterator(); - } - _lastNode = _iterators[_iterators.length - 1].getNode(); - } - - - public boolean atTail() - { - for(int i = 0; i < _iterators.length; i++) - { - if(!_iterators[i].atTail()) - { - return false; - } - } - return true; - } - - public SimpleQueueEntryImpl getNode() - { - return _lastNode; - } - - public boolean advance() - { - for(int i = _iterators.length-1; i >= 0; i--) - { - if(_iterators[i].advance()) - { - _lastNode = _iterators[i].getNode(); - return true; - } - } - return false; - } - } - - public PriorityQueueEntryListIterator iterator() - { - return new PriorityQueueEntryListIterator(); - } - - public SimpleQueueEntryImpl getHead() - { - return _priorityLists[_priorities-1].getHead(); - } - - public void entryDeleted(final SimpleQueueEntryImpl queueEntry) - { - - } - - static class Factory implements QueueEntryListFactory - { - private final int _priorities; - - Factory(int priorities) - { - _priorities = priorities; - } - - public PriorityQueueList createQueueEntryList(AMQQueue queue) - { - return new PriorityQueueList(queue, _priorities); - } - } - - private static class PriorityQueueEntrySubList extends SimpleQueueEntryList - { - private int _listPriority; - - public PriorityQueueEntrySubList(AMQQueue queue, int listPriority) - { - super(queue); - _listPriority = listPriority; - } - - @Override - protected PriorityQueueEntryImpl createQueueEntry(ServerMessage<?> message) - { - return new PriorityQueueEntryImpl(this, message); - } - - public int getListPriority() - { - return _listPriority; - } - } - - private static class PriorityQueueEntryImpl extends SimpleQueueEntryImpl - { - public PriorityQueueEntryImpl(PriorityQueueEntrySubList queueEntryList, ServerMessage<?> message) - { - super(queueEntryList, message); - } - - @Override - public int compareTo(final QueueEntry o) - { - PriorityQueueEntrySubList pqel = (PriorityQueueEntrySubList)((PriorityQueueEntryImpl)o).getQueueEntryList(); - int otherPriority = pqel.getListPriority(); - int thisPriority = ((PriorityQueueEntrySubList) getQueueEntryList()).getListPriority(); - - if(thisPriority != otherPriority) - { - /* - * Different priorities, so answer can only be greater than or less than - * - * A message with higher priority (e.g. 5) is conceptually 'earlier' in the - * priority queue than one with a lower priority (e.g. 4). - */ - return thisPriority > otherPriority ? -1 : 1; - } - else - { - return super.compareTo(o); - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueArgumentsConverter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueArgumentsConverter.java deleted file mode 100644 index 589f385d22..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueArgumentsConverter.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import org.apache.qpid.server.model.Queue; - -public class QueueArgumentsConverter -{ - public static final String X_QPID_FLOW_RESUME_CAPACITY = "x-qpid-flow-resume-capacity"; - public static final String X_QPID_CAPACITY = "x-qpid-capacity"; - public static final String X_QPID_MINIMUM_ALERT_REPEAT_GAP = "x-qpid-minimum-alert-repeat-gap"; - public static final String X_QPID_MAXIMUM_MESSAGE_COUNT = "x-qpid-maximum-message-count"; - public static final String X_QPID_MAXIMUM_MESSAGE_SIZE = "x-qpid-maximum-message-size"; - public static final String X_QPID_MAXIMUM_MESSAGE_AGE = "x-qpid-maximum-message-age"; - public static final String X_QPID_MAXIMUM_QUEUE_DEPTH = "x-qpid-maximum-queue-depth"; - - public static final String QPID_ALERT_COUNT = "qpid.alert_count"; - public static final String QPID_ALERT_SIZE = "qpid.alert_size"; - public static final String QPID_ALERT_REPEAT_GAP = "qpid.alert_repeat_gap"; - - public static final String X_QPID_PRIORITIES = "x-qpid-priorities"; - - public static final String X_QPID_DESCRIPTION = "x-qpid-description"; - - public static final String QPID_LAST_VALUE_QUEUE_KEY = "qpid.last_value_queue_key"; - - public static final String QPID_QUEUE_SORT_KEY = "qpid.queue_sort_key"; - public static final String X_QPID_DLQ_ENABLED = "x-qpid-dlq-enabled"; - public static final String X_QPID_MAXIMUM_DELIVERY_COUNT = "x-qpid-maximum-delivery-count"; - public static final String QPID_GROUP_HEADER_KEY = "qpid.group_header_key"; - public static final String QPID_SHARED_MSG_GROUP = "qpid.shared_msg_group"; - public static final String QPID_DEFAULT_MESSAGE_GROUP_ARG = "qpid.default-message-group"; - public static final String QPID_TRACE_EXCLUDE = "qpid.trace.exclude"; - public static final String QPID_TRACE_ID = "qpid.trace.id"; - - public static final String QPID_LAST_VALUE_QUEUE = "qpid.last_value_queue"; - - /** - * No-local queue argument is used to support the no-local feature of Durable Subscribers. - */ - public static final String QPID_NO_LOCAL = "no-local"; - static final Map<String, String> ATTRIBUTE_MAPPINGS = new LinkedHashMap<String, String>(); - static - { - ATTRIBUTE_MAPPINGS.put(X_QPID_MINIMUM_ALERT_REPEAT_GAP, Queue.ALERT_REPEAT_GAP); - ATTRIBUTE_MAPPINGS.put(X_QPID_MAXIMUM_MESSAGE_AGE, Queue.ALERT_THRESHOLD_MESSAGE_AGE); - ATTRIBUTE_MAPPINGS.put(X_QPID_MAXIMUM_MESSAGE_SIZE, Queue.ALERT_THRESHOLD_MESSAGE_SIZE); - - ATTRIBUTE_MAPPINGS.put(X_QPID_MAXIMUM_MESSAGE_COUNT, Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES); - ATTRIBUTE_MAPPINGS.put(X_QPID_MAXIMUM_QUEUE_DEPTH, Queue.ALERT_THRESHOLD_QUEUE_DEPTH_BYTES); - ATTRIBUTE_MAPPINGS.put(QPID_ALERT_COUNT, Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES); - ATTRIBUTE_MAPPINGS.put(QPID_ALERT_SIZE, Queue.ALERT_THRESHOLD_QUEUE_DEPTH_BYTES); - ATTRIBUTE_MAPPINGS.put(QPID_ALERT_REPEAT_GAP, Queue.ALERT_REPEAT_GAP); - - ATTRIBUTE_MAPPINGS.put(X_QPID_MAXIMUM_DELIVERY_COUNT, Queue.MAXIMUM_DELIVERY_ATTEMPTS); - - ATTRIBUTE_MAPPINGS.put(X_QPID_CAPACITY, Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES); - ATTRIBUTE_MAPPINGS.put(X_QPID_FLOW_RESUME_CAPACITY, Queue.QUEUE_FLOW_RESUME_SIZE_BYTES); - - ATTRIBUTE_MAPPINGS.put(QPID_QUEUE_SORT_KEY, Queue.SORT_KEY); - ATTRIBUTE_MAPPINGS.put(QPID_LAST_VALUE_QUEUE_KEY, Queue.LVQ_KEY); - ATTRIBUTE_MAPPINGS.put(X_QPID_PRIORITIES, Queue.PRIORITIES); - - ATTRIBUTE_MAPPINGS.put(X_QPID_DESCRIPTION, Queue.DESCRIPTION); - - ATTRIBUTE_MAPPINGS.put(X_QPID_DLQ_ENABLED, Queue.CREATE_DLQ_ON_CREATION); - ATTRIBUTE_MAPPINGS.put(QPID_GROUP_HEADER_KEY, Queue.MESSAGE_GROUP_KEY); - //ATTRIBUTE_MAPPINGS.put(QPID_SHARED_MSG_GROUP, Queue.MESSAGE_GROUP_SHARED_GROUPS); - ATTRIBUTE_MAPPINGS.put(QPID_DEFAULT_MESSAGE_GROUP_ARG, Queue.MESSAGE_GROUP_DEFAULT_GROUP); - ATTRIBUTE_MAPPINGS.put(QPID_TRACE_EXCLUDE, Queue.FEDERATION_EXCLUDES); - ATTRIBUTE_MAPPINGS.put(QPID_TRACE_ID, Queue.FEDERATION_ID); - ATTRIBUTE_MAPPINGS.put(QPID_NO_LOCAL, Queue.NO_LOCAL); - - } - - - public static Map<String,Object> convertWireArgsToModel(Map<String,Object> wireArguments) - { - Map<String,Object> modelArguments = new HashMap<String, Object>(); - if(wireArguments != null) - { - for(Map.Entry<String,String> entry : ATTRIBUTE_MAPPINGS.entrySet()) - { - if(wireArguments.containsKey(entry.getKey())) - { - modelArguments.put(entry.getValue(), wireArguments.get(entry.getKey())); - } - } - if(wireArguments.containsKey(QPID_LAST_VALUE_QUEUE) && !wireArguments.containsKey(QPID_LAST_VALUE_QUEUE_KEY)) - { - modelArguments.put(Queue.LVQ_KEY, AMQQueueFactory.QPID_DEFAULT_LVQ_KEY); - } - if(wireArguments.containsKey(QPID_SHARED_MSG_GROUP)) - { - modelArguments.put(Queue.MESSAGE_GROUP_SHARED_GROUPS, - SimpleAMQQueue.SHARED_MSG_GROUP_ARG_VALUE.equals(String.valueOf(wireArguments.get(QPID_SHARED_MSG_GROUP)))); - } - if(wireArguments.get(X_QPID_DLQ_ENABLED) != null) - { - modelArguments.put(Queue.CREATE_DLQ_ON_CREATION, Boolean.parseBoolean(wireArguments.get(X_QPID_DLQ_ENABLED).toString())); - } - - if(wireArguments.get(QPID_NO_LOCAL) != null) - { - modelArguments.put(Queue.NO_LOCAL, Boolean.parseBoolean(wireArguments.get(QPID_NO_LOCAL).toString())); - } - - } - return modelArguments; - } - - - public static Map<String,Object> convertModelArgsToWire(Map<String,Object> modelArguments) - { - Map<String,Object> wireArguments = new HashMap<String, Object>(); - for(Map.Entry<String,String> entry : ATTRIBUTE_MAPPINGS.entrySet()) - { - if(modelArguments.containsKey(entry.getValue())) - { - wireArguments.put(entry.getKey(), modelArguments.get(entry.getValue())); - } - } - - if(Boolean.TRUE.equals(modelArguments.get(Queue.MESSAGE_GROUP_SHARED_GROUPS))) - { - wireArguments.put(QPID_SHARED_MSG_GROUP, SimpleAMQQueue.SHARED_MSG_GROUP_ARG_VALUE); - } - - return wireArguments; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueContext.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueContext.java deleted file mode 100755 index 79279b44c7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueContext.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -final class QueueContext implements AMQQueue.Context -{ - private volatile QueueEntry _lastSeenEntry; - private volatile QueueEntry _releasedEntry; - - static final AtomicReferenceFieldUpdater<QueueContext, QueueEntry> - _lastSeenUpdater = - AtomicReferenceFieldUpdater.newUpdater - (QueueContext.class, QueueEntry.class, "_lastSeenEntry"); - static final AtomicReferenceFieldUpdater<QueueContext, QueueEntry> - _releasedUpdater = - AtomicReferenceFieldUpdater.newUpdater - (QueueContext.class, QueueEntry.class, "_releasedEntry"); - - public QueueContext(QueueEntry head) - { - _lastSeenEntry = head; - } - - public QueueEntry getLastSeenEntry() - { - return _lastSeenEntry; - } - - - QueueEntry getReleasedEntry() - { - return _releasedEntry; - } - - @Override - public String toString() - { - return "QueueContext{" + - "_lastSeenEntry=" + _lastSeenEntry + - ", _releasedEntry=" + _releasedEntry + - '}'; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java deleted file mode 100644 index c44961c457..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java +++ /dev/null @@ -1,253 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.queue; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.subscription.Subscription; - -public interface QueueEntry extends Comparable<QueueEntry>, Filterable -{ - - - - public static enum State - { - AVAILABLE, - ACQUIRED, - EXPIRED, - DEQUEUED, - DELETED; - - - } - - public static interface StateChangeListener - { - public void stateChanged(QueueEntry entry, State oldSate, State newState); - } - - public abstract class EntryState - { - private EntryState() - { - } - - public abstract State getState(); - - /** - * Returns true if state is either DEQUEUED or DELETED. - * - * @return true if state is either DEQUEUED or DELETED. - */ - public boolean isDispensed() - { - State currentState = getState(); - return currentState == State.DEQUEUED || currentState == State.DELETED; - } - } - - - public final class AvailableState extends EntryState - { - - public State getState() - { - return State.AVAILABLE; - } - - public String toString() - { - return getState().name(); - } - } - - - public final class DequeuedState extends EntryState - { - - public State getState() - { - return State.DEQUEUED; - } - - public String toString() - { - return getState().name(); - } - } - - - public final class DeletedState extends EntryState - { - - public State getState() - { - return State.DELETED; - } - - public String toString() - { - return getState().name(); - } - } - - public final class ExpiredState extends EntryState - { - - public State getState() - { - return State.EXPIRED; - } - - public String toString() - { - return getState().name(); - } - } - - - public final class NonSubscriptionAcquiredState extends EntryState - { - public State getState() - { - return State.ACQUIRED; - } - - public String toString() - { - return getState().name(); - } - } - - public final class SubscriptionAcquiredState extends EntryState - { - private final Subscription _subscription; - - public SubscriptionAcquiredState(Subscription subscription) - { - _subscription = subscription; - } - - - public State getState() - { - return State.ACQUIRED; - } - - public Subscription getSubscription() - { - return _subscription; - } - - public String toString() - { - return "{" + getState().name() + " : " + _subscription +"}"; - } - } - - - final static EntryState AVAILABLE_STATE = new AvailableState(); - final static EntryState DELETED_STATE = new DeletedState(); - final static EntryState DEQUEUED_STATE = new DequeuedState(); - final static EntryState NON_SUBSCRIPTION_ACQUIRED_STATE = new NonSubscriptionAcquiredState(); - - - - - AMQQueue getQueue(); - - ServerMessage getMessage(); - - long getSize(); - - boolean getDeliveredToConsumer(); - - boolean expired() throws AMQException; - - boolean isAvailable(); - - boolean isAcquired(); - - boolean acquire(); - boolean acquire(Subscription sub); - - boolean delete(); - boolean isDeleted(); - - boolean acquiredBySubscription(); - boolean isAcquiredBy(Subscription subscription); - - void release(); - - void setRedelivered(); - - boolean isRedelivered(); - - Subscription getDeliveredSubscription(); - - void reject(); - - boolean isRejectedBy(long subscriptionId); - - void dequeue(); - - void dispose(); - - void discard(); - - void routeToAlternate(); - - boolean isQueueDeleted(); - - QueueEntry getNextNode(); - - QueueEntry getNextValidEntry(); - - void addStateChangeListener(StateChangeListener listener); - boolean removeStateChangeListener(StateChangeListener listener); - - /** - * Returns true if entry is in DEQUEUED state, otherwise returns false. - * - * @return true if entry is in DEQUEUED state, otherwise returns false - */ - boolean isDequeued(); - - /** - * Returns true if entry is either DEQUED or DELETED state. - * - * @return true if entry is either DEQUED or DELETED state - */ - boolean isDispensed(); - - /** - * Number of times this queue entry has been delivered. - * - * @return delivery count - */ - int getDeliveryCount(); - - void incrementDeliveryCount(); - - void decrementDeliveryCount(); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryImpl.java deleted file mode 100644 index 36feb27d86..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryImpl.java +++ /dev/null @@ -1,517 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.message.AMQMessageHeader; -import org.apache.qpid.server.message.MessageReference; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.server.txn.LocalTransaction; -import org.apache.qpid.server.txn.ServerTransaction; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; -import java.util.concurrent.atomic.AtomicLongFieldUpdater; -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -public abstract class QueueEntryImpl implements QueueEntry -{ - private static final Logger _log = Logger.getLogger(QueueEntryImpl.class); - - private final QueueEntryList _queueEntryList; - - private MessageReference _message; - - private Set<Long> _rejectedBy = null; - - private volatile EntryState _state = AVAILABLE_STATE; - - private static final - AtomicReferenceFieldUpdater<QueueEntryImpl, EntryState> - _stateUpdater = - AtomicReferenceFieldUpdater.newUpdater - (QueueEntryImpl.class, EntryState.class, "_state"); - - - private volatile Set<StateChangeListener> _stateChangeListeners; - - private static final - AtomicReferenceFieldUpdater<QueueEntryImpl, Set> - _listenersUpdater = - AtomicReferenceFieldUpdater.newUpdater - (QueueEntryImpl.class, Set.class, "_stateChangeListeners"); - - - private static final - AtomicLongFieldUpdater<QueueEntryImpl> - _entryIdUpdater = - AtomicLongFieldUpdater.newUpdater - (QueueEntryImpl.class, "_entryId"); - - - private volatile long _entryId; - - private static final int DELIVERED_TO_CONSUMER = 1; - private static final int REDELIVERED = 2; - - private volatile int _deliveryState; - - /** Number of times this message has been delivered */ - private volatile int _deliveryCount = 0; - private static final AtomicIntegerFieldUpdater<QueueEntryImpl> _deliveryCountUpdater = AtomicIntegerFieldUpdater - .newUpdater(QueueEntryImpl.class, "_deliveryCount"); - - - - public QueueEntryImpl(QueueEntryList<?> queueEntryList) - { - this(queueEntryList,null,Long.MIN_VALUE); - _state = DELETED_STATE; - } - - - public QueueEntryImpl(QueueEntryList<?> queueEntryList, ServerMessage message, final long entryId) - { - _queueEntryList = queueEntryList; - - _message = message == null ? null : message.newReference(); - - _entryIdUpdater.set(this, entryId); - } - - public QueueEntryImpl(QueueEntryList<?> queueEntryList, ServerMessage message) - { - _queueEntryList = queueEntryList; - _message = message == null ? null : message.newReference(); - } - - protected void setEntryId(long entryId) - { - _entryIdUpdater.set(this, entryId); - } - - protected long getEntryId() - { - return _entryId; - } - - public AMQQueue getQueue() - { - return _queueEntryList.getQueue(); - } - - public ServerMessage getMessage() - { - return _message == null ? null : _message.getMessage(); - } - - public long getSize() - { - return getMessage() == null ? 0 : getMessage().getSize(); - } - - public boolean getDeliveredToConsumer() - { - return (_deliveryState & DELIVERED_TO_CONSUMER) != 0; - } - - public boolean expired() throws AMQException - { - ServerMessage message = getMessage(); - if(message != null) - { - long expiration = message.getExpiration(); - if (expiration != 0L) - { - long now = System.currentTimeMillis(); - - return (now > expiration); - } - } - return false; - - } - - public boolean isAvailable() - { - return _state == AVAILABLE_STATE; - } - - public boolean isAcquired() - { - return _state.getState() == State.ACQUIRED; - } - - public boolean acquire() - { - return acquire(NON_SUBSCRIPTION_ACQUIRED_STATE); - } - - private boolean acquire(final EntryState state) - { - boolean acquired = _stateUpdater.compareAndSet(this,AVAILABLE_STATE, state); - - if(acquired && _stateChangeListeners != null) - { - notifyStateChange(State.AVAILABLE, State.ACQUIRED); - } - - return acquired; - } - - public boolean acquire(Subscription sub) - { - final boolean acquired = acquire(sub.getOwningState()); - if(acquired) - { - _deliveryState |= DELIVERED_TO_CONSUMER; - } - return acquired; - } - - public boolean acquiredBySubscription() - { - - return (_state instanceof SubscriptionAcquiredState); - } - - public boolean isAcquiredBy(Subscription subscription) - { - EntryState state = _state; - return state instanceof SubscriptionAcquiredState - && ((SubscriptionAcquiredState)state).getSubscription() == subscription; - } - - public void release() - { - EntryState state = _state; - - if((state.getState() == State.ACQUIRED) &&_stateUpdater.compareAndSet(this, state, AVAILABLE_STATE)) - { - - if(state instanceof SubscriptionAcquiredState) - { - getQueue().decrementUnackedMsgCount(this); - Subscription subscription = ((SubscriptionAcquiredState)state).getSubscription(); - if (subscription != null) - { - subscription.releaseQueueEntry(this); - } - } - - if(!getQueue().isDeleted()) - { - getQueue().requeue(this); - if(_stateChangeListeners != null) - { - notifyStateChange(QueueEntry.State.ACQUIRED, QueueEntry.State.AVAILABLE); - } - - } - else if(acquire()) - { - routeToAlternate(); - } - } - - } - - public void setRedelivered() - { - _deliveryState |= REDELIVERED; - } - - public AMQMessageHeader getMessageHeader() - { - final ServerMessage message = getMessage(); - return message == null ? null : message.getMessageHeader(); - } - - public boolean isPersistent() - { - final ServerMessage message = getMessage(); - return message != null && message.isPersistent(); - } - - public boolean isRedelivered() - { - return (_deliveryState & REDELIVERED) != 0; - } - - public Subscription getDeliveredSubscription() - { - EntryState state = _state; - if (state instanceof SubscriptionAcquiredState) - { - return ((SubscriptionAcquiredState) state).getSubscription(); - } - else - { - return null; - } - } - - public void reject() - { - Subscription subscription = getDeliveredSubscription(); - - if (subscription != null) - { - if (_rejectedBy == null) - { - _rejectedBy = new HashSet<Long>(); - } - - _rejectedBy.add(subscription.getSubscriptionID()); - } - else - { - _log.warn("Requesting rejection by null subscriber:" + this); - } - } - - public boolean isRejectedBy(long subscriptionId) - { - - if (_rejectedBy != null) // We have subscriptions that rejected this message - { - return _rejectedBy.contains(subscriptionId); - } - else // This messasge hasn't been rejected yet. - { - return false; - } - } - - public void dequeue() - { - EntryState state = _state; - - if((state.getState() == State.ACQUIRED) &&_stateUpdater.compareAndSet(this, state, DEQUEUED_STATE)) - { - Subscription s = null; - if (state instanceof SubscriptionAcquiredState) - { - getQueue().decrementUnackedMsgCount(this); - s = ((SubscriptionAcquiredState) state).getSubscription(); - s.onDequeue(this); - } - - getQueue().dequeue(this,s); - if(_stateChangeListeners != null) - { - notifyStateChange(state.getState() , QueueEntry.State.DEQUEUED); - } - - } - - } - - private void notifyStateChange(final State oldState, final State newState) - { - for(StateChangeListener l : _stateChangeListeners) - { - l.stateChanged(this, oldState, newState); - } - } - - public void dispose() - { - if(delete()) - { - _message.release(); - } - } - - public void discard() - { - //if the queue is null then the message is waiting to be acked, but has been removed. - if (getQueue() != null) - { - dequeue(); - } - - dispose(); - } - - public void routeToAlternate() - { - final AMQQueue currentQueue = getQueue(); - Exchange alternateExchange = currentQueue.getAlternateExchange(); - - if (alternateExchange != null) - { - InboundMessageAdapter inboundMessageAdapter = new InboundMessageAdapter(this); - List<? extends BaseQueue> queues = alternateExchange.route(inboundMessageAdapter); - final ServerMessage message = getMessage(); - if ((queues == null || queues.size() == 0) && alternateExchange.getAlternateExchange() != null) - { - queues = alternateExchange.getAlternateExchange().route(inboundMessageAdapter); - } - - - - if (queues != null && queues.size() != 0) - { - final List<? extends BaseQueue> rerouteQueues = queues; - ServerTransaction txn = new LocalTransaction(getQueue().getVirtualHost().getMessageStore()); - - txn.enqueue(rerouteQueues, message, new ServerTransaction.Action() - { - public void postCommit() - { - try - { - for (BaseQueue queue : rerouteQueues) - { - queue.enqueue(message); - } - } - catch (AMQException e) - { - throw new RuntimeException(e); - } - } - - public void onRollback() - { - - } - }); - - txn.dequeue(currentQueue, message, new ServerTransaction.Action() - { - public void postCommit() - { - discard(); - } - - public void onRollback() - { - - } - }); - - txn.commit(); - } - } - } - - public boolean isQueueDeleted() - { - return getQueue().isDeleted(); - } - - public void addStateChangeListener(StateChangeListener listener) - { - Set<StateChangeListener> listeners = _stateChangeListeners; - if(listeners == null) - { - _listenersUpdater.compareAndSet(this, null, new CopyOnWriteArraySet<StateChangeListener>()); - listeners = _stateChangeListeners; - } - - listeners.add(listener); - } - - public boolean removeStateChangeListener(StateChangeListener listener) - { - Set<StateChangeListener> listeners = _stateChangeListeners; - if(listeners != null) - { - return listeners.remove(listener); - } - - return false; - } - - - public int compareTo(final QueueEntry o) - { - QueueEntryImpl other = (QueueEntryImpl)o; - return getEntryId() > other.getEntryId() ? 1 : getEntryId() < other.getEntryId() ? -1 : 0; - } - - public boolean isDeleted() - { - return _state == DELETED_STATE; - } - - public boolean delete() - { - EntryState state = _state; - - if(state != DELETED_STATE && _stateUpdater.compareAndSet(this,state,DELETED_STATE)) - { - _queueEntryList.entryDeleted(this); - return true; - } - else - { - return false; - } - } - - public QueueEntryList getQueueEntryList() - { - return _queueEntryList; - } - - public boolean isDequeued() - { - return _state == DEQUEUED_STATE; - } - - public boolean isDispensed() - { - return _state.isDispensed(); - } - - public int getDeliveryCount() - { - return _deliveryCount; - } - - public void incrementDeliveryCount() - { - _deliveryCountUpdater.incrementAndGet(this); - } - - public void decrementDeliveryCount() - { - _deliveryCountUpdater.decrementAndGet(this); - } - - public String toString() - { - return "QueueEntryImpl{" + - "_entryId=" + _entryId + - ", _state=" + _state + - '}'; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryIterator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryIterator.java deleted file mode 100644 index 73ebb0f300..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryIterator.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.queue; - -public interface QueueEntryIterator<QE extends QueueEntry> -{ - boolean atTail(); - - QE getNode(); - - boolean advance(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryList.java deleted file mode 100644 index 641aaa0a08..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryList.java +++ /dev/null @@ -1,40 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.queue; - -import org.apache.qpid.server.message.ServerMessage; - -public interface QueueEntryList<Q extends QueueEntry> -{ - AMQQueue getQueue(); - - Q add(ServerMessage message); - - Q next(Q node); - - QueueEntryIterator<Q> iterator(); - - Q getHead(); - - void entryDeleted(Q queueEntry); - - int getPriorities(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryListFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryListFactory.java deleted file mode 100644 index 4dbce45f67..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryListFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.queue; - -interface QueueEntryListFactory -{ - public QueueEntryList createQueueEntryList(AMQQueue queue); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryVisitor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryVisitor.java deleted file mode 100644 index 9ecaf6dafd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryVisitor.java +++ /dev/null @@ -1,22 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You 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.qpid.server.queue; - -public interface QueueEntryVisitor -{ - boolean visit(QueueEntry entry); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueFactory.java deleted file mode 100644 index 3e4e1df5a2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import java.util.Map; -import java.util.UUID; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; - -public interface QueueFactory -{ - AMQQueue createQueue(UUID id, - String queueName, - boolean durable, - String owner, - boolean autoDelete, - boolean exclusive, - boolean deleteOnNoConsumer, - Map<String, Object> arguments) throws AMQSecurityException, AMQException; - - AMQQueue restoreQueue(UUID id, - String queueName, - String owner, - boolean autoDelete, - boolean exclusive, - boolean deleteOnNoConsumer, - Map<String, Object> arguments) throws AMQSecurityException, AMQException; - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueRegistry.java deleted file mode 100644 index bc1d5942bd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueRegistry.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.Collection; -import java.util.UUID; - -public interface QueueRegistry -{ - VirtualHost getVirtualHost(); - - void registerQueue(AMQQueue queue); - - void unregisterQueue(String name); - - Collection<AMQQueue> getQueues(); - - AMQQueue getQueue(String queue); - - void addRegistryChangeListener(RegistryChangeListener listener); - - void stopAllAndUnregisterMBeans(); - - AMQQueue getQueue(UUID queueId); - - interface RegistryChangeListener - { - void queueRegistered(AMQQueue queue); - void queueUnregistered(AMQQueue queue); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueRunner.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueRunner.java deleted file mode 100644 index 22a2029494..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/QueueRunner.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import java.util.concurrent.Executor; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.transport.TransportException; - -/** - * QueueRunners are Runnables used to process a queue when requiring - * asynchronous message delivery to subscriptions, which is necessary - * when straight-through delivery of a message to a subscription isn't - * possible during the enqueue operation. - */ -public class QueueRunner implements Runnable -{ - private static final Logger _logger = Logger.getLogger(QueueRunner.class); - - private final SimpleAMQQueue _queue; - - private static int IDLE = 0; - private static int SCHEDULED = 1; - private static int RUNNING = 2; - - private final AtomicInteger _scheduled = new AtomicInteger(IDLE); - - private final AtomicBoolean _stateChange = new AtomicBoolean(); - - private final AtomicLong _lastRunAgain = new AtomicLong(); - private final AtomicLong _lastRunTime = new AtomicLong(); - - public QueueRunner(SimpleAMQQueue queue) - { - _queue = queue; - } - - public void run() - { - if(_scheduled.compareAndSet(SCHEDULED,RUNNING)) - { - long runAgain = Long.MIN_VALUE; - _stateChange.set(false); - try - { - CurrentActor.set(_queue.getLogActor()); - - runAgain = _queue.processQueue(this); - } - catch (final AMQException e) - { - _logger.error("Exception during asynchronous delivery by " + toString(), e); - } - catch (final TransportException transe) - { - final String errorMessage = "Problem during asynchronous delivery by " + toString(); - if(_logger.isDebugEnabled()) - { - _logger.debug(errorMessage, transe); - } - else - { - _logger.info(errorMessage + ' ' + transe.getMessage()); - } - } - finally - { - CurrentActor.remove(); - _scheduled.compareAndSet(RUNNING, IDLE); - final long stateChangeCount = _queue.getStateChangeCount(); - _lastRunAgain.set(runAgain); - _lastRunTime.set(System.nanoTime()); - if(runAgain == 0L || runAgain != stateChangeCount || _stateChange.compareAndSet(true,false)) - { - if(_scheduled.compareAndSet(IDLE, SCHEDULED)) - { - _queue.execute(this); - } - } - } - - } - } - - public String toString() - { - return "QueueRunner-" + _queue.getLogActor(); - } - - public void execute(Executor executor) - { - _stateChange.set(true); - if(_scheduled.compareAndSet(IDLE, SCHEDULED)) - { - executor.execute(this); - } - } - - public boolean isIdle() - { - return _scheduled.get() == IDLE; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java deleted file mode 100644 index fb36433799..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java +++ /dev/null @@ -1,2289 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentSkipListSet; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.Executor; -import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.pool.ReferenceCountingExecutorService; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.configuration.QueueConfiguration; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.actors.QueueActor; -import org.apache.qpid.server.logging.messages.QueueMessages; -import org.apache.qpid.server.logging.subjects.QueueLogSubject; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.security.AuthorizationHolder; -import org.apache.qpid.server.subscription.AssignedSubscriptionMessageGroupManager; -import org.apache.qpid.server.subscription.DefinedGroupMessageGroupManager; -import org.apache.qpid.server.subscription.MessageGroupManager; -import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.server.subscription.SubscriptionList; -import org.apache.qpid.server.txn.AutoCommitTransaction; -import org.apache.qpid.server.txn.LocalTransaction; -import org.apache.qpid.server.txn.ServerTransaction; -import org.apache.qpid.server.virtualhost.VirtualHost; - -public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, MessageGroupManager.SubscriptionResetHelper -{ - - private static final Logger _logger = Logger.getLogger(SimpleAMQQueue.class); - - public static final String SHARED_MSG_GROUP_ARG_VALUE = "1"; - private static final String QPID_NO_GROUP = "qpid.no-group"; - private static final String DEFAULT_SHARED_MESSAGE_GROUP = System.getProperty(BrokerProperties.PROPERTY_DEFAULT_SHARED_MESSAGE_GROUP, QPID_NO_GROUP); - - // TODO - should make this configurable at the vhost / broker level - private static final int DEFAULT_MAX_GROUPS = 255; - - private final VirtualHost _virtualHost; - - private final String _name; - - /** null means shared */ - private final String _owner; - - private AuthorizationHolder _authorizationHolder; - - private boolean _exclusive = false; - private AMQSessionModel _exclusiveOwner; - - - private final boolean _durable; - - /** If true, this queue is deleted when the last subscriber is removed */ - private final boolean _autoDelete; - - private Exchange _alternateExchange; - - - private final QueueEntryList<QueueEntry> _entries; - - private final SubscriptionList _subscriptionList = new SubscriptionList(); - - private volatile Subscription _exclusiveSubscriber; - - - - private final AtomicInteger _atomicQueueCount = new AtomicInteger(0); - - private final AtomicLong _atomicQueueSize = new AtomicLong(0L); - - private final AtomicInteger _activeSubscriberCount = new AtomicInteger(); - - private final AtomicLong _totalMessagesReceived = new AtomicLong(); - - private final AtomicLong _dequeueCount = new AtomicLong(); - private final AtomicLong _dequeueSize = new AtomicLong(); - private final AtomicLong _enqueueCount = new AtomicLong(); - private final AtomicLong _enqueueSize = new AtomicLong(); - private final AtomicLong _persistentMessageEnqueueSize = new AtomicLong(); - private final AtomicLong _persistentMessageDequeueSize = new AtomicLong(); - private final AtomicLong _persistentMessageEnqueueCount = new AtomicLong(); - private final AtomicLong _persistentMessageDequeueCount = new AtomicLong(); - private final AtomicInteger _counsumerCountHigh = new AtomicInteger(0); - private final AtomicLong _msgTxnEnqueues = new AtomicLong(0); - private final AtomicLong _byteTxnEnqueues = new AtomicLong(0); - private final AtomicLong _msgTxnDequeues = new AtomicLong(0); - private final AtomicLong _byteTxnDequeues = new AtomicLong(0); - private final AtomicLong _unackedMsgCount = new AtomicLong(0); - private final AtomicLong _unackedMsgCountHigh = new AtomicLong(0); - private final AtomicLong _unackedMsgBytes = new AtomicLong(); - - private final AtomicInteger _bindingCountHigh = new AtomicInteger(); - - /** max allowed size(KB) of a single message */ - private long _maximumMessageSize; - - /** max allowed number of messages on a queue. */ - private long _maximumMessageCount; - - /** max queue depth for the queue */ - private long _maximumQueueDepth; - - /** maximum message age before alerts occur */ - private long _maximumMessageAge; - - /** the minimum interval between sending out consecutive alerts of the same type */ - private long _minimumAlertRepeatGap; - - private long _capacity; - - private long _flowResumeCapacity; - - private final Set<NotificationCheck> _notificationChecks = EnumSet.noneOf(NotificationCheck.class); - - - static final int MAX_ASYNC_DELIVERIES = 80; - - - private final AtomicLong _stateChangeCount = new AtomicLong(Long.MIN_VALUE); - - private final Executor _asyncDelivery; - private AtomicInteger _deliveredMessages = new AtomicInteger(); - private AtomicBoolean _stopped = new AtomicBoolean(false); - - private final Set<AMQSessionModel> _blockedChannels = new ConcurrentSkipListSet<AMQSessionModel>(); - - private final AtomicBoolean _deleted = new AtomicBoolean(false); - private final List<Task> _deleteTaskList = new CopyOnWriteArrayList<Task>(); - - - private LogSubject _logSubject; - private LogActor _logActor; - - private static final String SUB_FLUSH_RUNNER = "SUB_FLUSH_RUNNER"; - private boolean _nolocal; - - private final AtomicBoolean _overfull = new AtomicBoolean(false); - private boolean _deleteOnNoConsumers; - private final CopyOnWriteArrayList<Binding> _bindings = new CopyOnWriteArrayList<Binding>(); - private UUID _id; - private final Map<String, Object> _arguments; - - //TODO : persist creation time - private long _createTime = System.currentTimeMillis(); - - /** the maximum delivery count for each message on this queue or 0 if maximum delivery count is not to be enforced. */ - private int _maximumDeliveryCount; - private final MessageGroupManager _messageGroupManager; - - private final Collection<SubscriptionRegistrationListener> _subscriptionListeners = - new ArrayList<SubscriptionRegistrationListener>(); - - private AMQQueue.NotificationListener _notificationListener; - private final long[] _lastNotificationTimes = new long[NotificationCheck.values().length]; - - - public SimpleAMQQueue(UUID id, String queueName, boolean durable, String owner, boolean autoDelete, boolean exclusive, VirtualHost virtualHost, Map<String, Object> arguments) - { - this(id, queueName, durable, owner, autoDelete, exclusive, virtualHost, new SimpleQueueEntryList.Factory(), arguments); - } - - protected SimpleAMQQueue(UUID id, - String name, - boolean durable, - String owner, - boolean autoDelete, - boolean exclusive, - VirtualHost virtualHost, - QueueEntryListFactory entryListFactory, Map<String,Object> arguments) - { - - if (name == null) - { - throw new IllegalArgumentException("Queue name must not be null"); - } - - if (virtualHost == null) - { - throw new IllegalArgumentException("Virtual Host must not be null"); - } - - _name = name; - _durable = durable; - _owner = owner; - _autoDelete = autoDelete; - _exclusive = exclusive; - _virtualHost = virtualHost; - _entries = entryListFactory.createQueueEntryList(this); - _arguments = Collections.synchronizedMap(arguments == null ? new LinkedHashMap<String, Object>() : new LinkedHashMap<String, Object>(arguments)); - - _id = id; - _asyncDelivery = ReferenceCountingExecutorService.getInstance().acquireExecutorService(); - - _logSubject = new QueueLogSubject(this); - _logActor = new QueueActor(this, CurrentActor.get().getRootMessageLogger()); - - // Log the creation of this Queue. - // The priorities display is toggled on if we set priorities > 0 - CurrentActor.get().message(_logSubject, - QueueMessages.CREATED(String.valueOf(_owner), - _entries.getPriorities(), - _owner != null, - autoDelete, - durable, !durable, - _entries.getPriorities() > 0)); - - if(arguments != null && arguments.containsKey(Queue.MESSAGE_GROUP_KEY)) - { - if(arguments.get(Queue.MESSAGE_GROUP_SHARED_GROUPS) != null - && (Boolean)(arguments.get(Queue.MESSAGE_GROUP_SHARED_GROUPS))) - { - Object defaultGroup = arguments.get(Queue.MESSAGE_GROUP_DEFAULT_GROUP); - _messageGroupManager = - new DefinedGroupMessageGroupManager(String.valueOf(arguments.get(Queue.MESSAGE_GROUP_KEY)), - defaultGroup == null ? DEFAULT_SHARED_MESSAGE_GROUP : defaultGroup.toString(), - this); - } - else - { - _messageGroupManager = new AssignedSubscriptionMessageGroupManager(String.valueOf(arguments.get( - Queue.MESSAGE_GROUP_KEY)), DEFAULT_MAX_GROUPS); - } - } - else - { - _messageGroupManager = null; - } - - resetNotifications(); - - } - - public void resetNotifications() - { - // This ensure that the notification checks for the configured alerts are created. - setMaximumMessageAge(_maximumMessageAge); - setMaximumMessageCount(_maximumMessageCount); - setMaximumMessageSize(_maximumMessageSize); - setMaximumQueueDepth(_maximumQueueDepth); - } - - // ------ Getters and Setters - - public void execute(Runnable runnable) - { - try - { - _asyncDelivery.execute(runnable); - } - catch (RejectedExecutionException ree) - { - if (_stopped.get()) - { - // Ignore - SubFlusherRunner or QueueRunner submitted execution as queue was being stopped. - } - else - { - _logger.error("Unexpected rejected execution", ree); - throw ree; - } - } - } - - public void setNoLocal(boolean nolocal) - { - _nolocal = nolocal; - } - - public UUID getId() - { - return _id; - } - - public boolean isDurable() - { - return _durable; - } - - public boolean isExclusive() - { - return _exclusive; - } - - public void setExclusive(boolean exclusive) - { - _exclusive = exclusive; - } - - public Exchange getAlternateExchange() - { - return _alternateExchange; - } - - public void setAlternateExchange(Exchange exchange) - { - if(_alternateExchange != null) - { - _alternateExchange.removeReference(this); - } - if(exchange != null) - { - exchange.addReference(this); - } - _alternateExchange = exchange; - } - - - @Override - public Collection<String> getAvailableAttributes() - { - return new ArrayList<String>(_arguments.keySet()); - } - - @Override - public Object getAttribute(String attrName) - { - return _arguments.get(attrName); - } - - public boolean isAutoDelete() - { - return _autoDelete; - } - - public String getOwner() - { - return _owner; - } - - public AuthorizationHolder getAuthorizationHolder() - { - return _authorizationHolder; - } - - public void setAuthorizationHolder(final AuthorizationHolder authorizationHolder) - { - _authorizationHolder = authorizationHolder; - } - - - public VirtualHost getVirtualHost() - { - return _virtualHost; - } - - public String getName() - { - return _name; - } - - // ------ Manage Subscriptions - - public synchronized void registerSubscription(final Subscription subscription, final boolean exclusive) - throws AMQSecurityException, ExistingExclusiveSubscription, ExistingSubscriptionPreventsExclusive - { - // Access control - if (!getVirtualHost().getSecurityManager().authoriseConsume(this)) - { - throw new AMQSecurityException("Permission denied"); - } - - - if (hasExclusiveSubscriber()) - { - throw new ExistingExclusiveSubscription(); - } - - if (exclusive && !subscription.isTransient()) - { - if (getConsumerCount() != 0) - { - throw new ExistingSubscriptionPreventsExclusive(); - } - else - { - _exclusiveSubscriber = subscription; - } - } - - if(subscription.isActive()) - { - _activeSubscriberCount.incrementAndGet(); - } - subscription.setStateListener(this); - subscription.setQueueContext(new QueueContext(_entries.getHead())); - - if (!isDeleted()) - { - subscription.setQueue(this, exclusive); - if(_nolocal) - { - subscription.setNoLocal(_nolocal); - } - - synchronized (_subscriptionListeners) - { - for(SubscriptionRegistrationListener listener : _subscriptionListeners) - { - listener.subscriptionRegistered(this, subscription); - } - } - - _subscriptionList.add(subscription); - - //Increment consumerCountHigh if necessary. (un)registerSubscription are both - //synchronized methods so we don't need additional synchronization here - if(_counsumerCountHigh.get() < getConsumerCount()) - { - _counsumerCountHigh.incrementAndGet(); - } - - if (isDeleted()) - { - subscription.queueDeleted(this); - } - } - else - { - // TODO - } - - deliverAsync(subscription); - - } - - public synchronized void unregisterSubscription(final Subscription subscription) throws AMQException - { - if (subscription == null) - { - throw new NullPointerException("subscription argument is null"); - } - - boolean removed = _subscriptionList.remove(subscription); - - if (removed) - { - subscription.close(); - // No longer can the queue have an exclusive consumer - setExclusiveSubscriber(null); - subscription.setQueueContext(null); - - if(_messageGroupManager != null) - { - resetSubPointersForGroups(subscription, true); - } - - synchronized (_subscriptionListeners) - { - for(SubscriptionRegistrationListener listener : _subscriptionListeners) - { - listener.subscriptionUnregistered(this, subscription); - } - } - - // auto-delete queues must be deleted if there are no remaining subscribers - - if (_autoDelete && getDeleteOnNoConsumers() && !subscription.isTransient() && getConsumerCount() == 0 ) - { - if (_logger.isInfoEnabled()) - { - _logger.info("Auto-deleteing queue:" + this); - } - - getVirtualHost().removeQueue(this); - - // we need to manually fire the event to the removed subscription (which was the last one left for this - // queue. This is because the delete method uses the subscription set which has just been cleared - subscription.queueDeleted(this); - } - } - - } - - public Collection<Subscription> getConsumers() - { - List<Subscription> consumers = new ArrayList<Subscription>(); - SubscriptionList.SubscriptionNodeIterator iter = _subscriptionList.iterator(); - while(iter.advance()) - { - consumers.add(iter.getNode().getSubscription()); - } - return consumers; - - } - - public void addSubscriptionRegistrationListener(final SubscriptionRegistrationListener listener) - { - synchronized (_subscriptionListeners) - { - _subscriptionListeners.add(listener); - } - } - - public void removeSubscriptionRegistrationListener(final SubscriptionRegistrationListener listener) - { - synchronized (_subscriptionListeners) - { - _subscriptionListeners.remove(listener); - } - } - - public void resetSubPointersForGroups(Subscription subscription, boolean clearAssignments) - { - QueueEntry entry = _messageGroupManager.findEarliestAssignedAvailableEntry(subscription); - if(clearAssignments) - { - _messageGroupManager.clearAssignments(subscription); - } - - if(entry != null) - { - SubscriptionList.SubscriptionNodeIterator subscriberIter = _subscriptionList.iterator(); - // iterate over all the subscribers, and if they are in advance of this queue entry then move them backwards - while (subscriberIter.advance()) - { - Subscription sub = subscriberIter.getNode().getSubscription(); - - // we don't make browsers send the same stuff twice - if (sub.seesRequeues()) - { - updateSubRequeueEntry(sub, entry); - } - } - - deliverAsync(); - - } - } - - public boolean getDeleteOnNoConsumers() - { - return _deleteOnNoConsumers; - } - - public void setDeleteOnNoConsumers(boolean b) - { - _deleteOnNoConsumers = b; - } - - public void addBinding(final Binding binding) - { - _bindings.add(binding); - int bindingCount = _bindings.size(); - int bindingCountHigh; - while(bindingCount > (bindingCountHigh = _bindingCountHigh.get())) - { - if(_bindingCountHigh.compareAndSet(bindingCountHigh, bindingCount)) - { - break; - } - } - } - - public int getBindingCountHigh() - { - return _bindingCountHigh.get(); - } - - public void removeBinding(final Binding binding) - { - _bindings.remove(binding); - } - - public List<Binding> getBindings() - { - return Collections.unmodifiableList(_bindings); - } - - public int getBindingCount() - { - return getBindings().size(); - } - - public LogSubject getLogSubject() - { - return _logSubject; - } - - // ------ Enqueue / Dequeue - public void enqueue(ServerMessage message) throws AMQException - { - enqueue(message, null); - } - - public void enqueue(ServerMessage message, PostEnqueueAction action) throws AMQException - { - enqueue(message, false, action); - } - - public void enqueue(ServerMessage message, boolean transactional, PostEnqueueAction action) throws AMQException - { - - if(transactional) - { - incrementTxnEnqueueStats(message); - } - incrementQueueCount(); - incrementQueueSize(message); - - _totalMessagesReceived.incrementAndGet(); - - - QueueEntry entry; - final Subscription exclusiveSub = _exclusiveSubscriber; - entry = _entries.add(message); - - if(action != null || (exclusiveSub == null && _queueRunner.isIdle())) - { - /* - - iterate over subscriptions and if any is at the end of the queue and can deliver this message, then deliver the message - - */ - SubscriptionList.SubscriptionNode node = _subscriptionList.getMarkedNode(); - SubscriptionList.SubscriptionNode nextNode = node.findNext(); - if (nextNode == null) - { - nextNode = _subscriptionList.getHead().findNext(); - } - while (nextNode != null) - { - if (_subscriptionList.updateMarkedNode(node, nextNode)) - { - break; - } - else - { - node = _subscriptionList.getMarkedNode(); - nextNode = node.findNext(); - if (nextNode == null) - { - nextNode = _subscriptionList.getHead().findNext(); - } - } - } - - // always do one extra loop after we believe we've finished - // this catches the case where we *just* miss an update - int loops = 2; - - while (entry.isAvailable() && loops != 0) - { - if (nextNode == null) - { - loops--; - nextNode = _subscriptionList.getHead(); - } - else - { - // if subscription at end, and active, offer - Subscription sub = nextNode.getSubscription(); - deliverToSubscription(sub, entry); - } - nextNode = nextNode.findNext(); - - } - } - - - if (entry.isAvailable()) - { - checkSubscriptionsNotAheadOfDelivery(entry); - - if (exclusiveSub != null) - { - deliverAsync(exclusiveSub); - } - else - { - deliverAsync(); - } - } - - checkForNotification(entry.getMessage()); - - if(action != null) - { - action.onEnqueue(entry); - } - - } - - private void deliverToSubscription(final Subscription sub, final QueueEntry entry) - throws AMQException - { - - if(sub.trySendLock()) - { - try - { - if (!sub.isSuspended() - && subscriptionReadyAndHasInterest(sub, entry) - && mightAssign(sub, entry) - && !sub.wouldSuspend(entry)) - { - if (sub.acquires() && !(assign(sub, entry) && entry.acquire(sub))) - { - // restore credit here that would have been taken away by wouldSuspend since we didn't manage - // to acquire the entry for this subscription - sub.restoreCredit(entry); - } - else - { - deliverMessage(sub, entry, false); - } - } - } - finally - { - sub.releaseSendLock(); - } - } - } - - private boolean assign(final Subscription sub, final QueueEntry entry) - { - return _messageGroupManager == null || _messageGroupManager.acceptMessage(sub, entry); - } - - - private boolean mightAssign(final Subscription sub, final QueueEntry entry) - { - if(_messageGroupManager == null || !sub.acquires()) - { - return true; - } - Subscription assigned = _messageGroupManager.getAssignedSubscription(entry); - return (assigned == null) || (assigned == sub); - } - - protected void checkSubscriptionsNotAheadOfDelivery(final QueueEntry entry) - { - // This method is only required for queues which mess with ordering - // Simple Queues don't :-) - } - - private void incrementQueueSize(final ServerMessage message) - { - long size = message.getSize(); - getAtomicQueueSize().addAndGet(size); - _enqueueCount.incrementAndGet(); - _enqueueSize.addAndGet(size); - if(message.isPersistent() && isDurable()) - { - _persistentMessageEnqueueSize.addAndGet(size); - _persistentMessageEnqueueCount.incrementAndGet(); - } - } - - public long getTotalDequeueCount() - { - return _dequeueCount.get(); - } - - public long getTotalEnqueueCount() - { - return _enqueueCount.get(); - } - - private void incrementQueueCount() - { - getAtomicQueueCount().incrementAndGet(); - } - - private void incrementTxnEnqueueStats(final ServerMessage message) - { - _msgTxnEnqueues.incrementAndGet(); - _byteTxnEnqueues.addAndGet(message.getSize()); - } - - private void incrementTxnDequeueStats(QueueEntry entry) - { - _msgTxnDequeues.incrementAndGet(); - _byteTxnDequeues.addAndGet(entry.getSize()); - } - - private void deliverMessage(final Subscription sub, final QueueEntry entry, boolean batch) - throws AMQException - { - setLastSeenEntry(sub, entry); - - _deliveredMessages.incrementAndGet(); - incrementUnackedMsgCount(entry); - - sub.send(entry, batch); - } - - private boolean subscriptionReadyAndHasInterest(final Subscription sub, final QueueEntry entry) throws AMQException - { - return sub.hasInterest(entry) && (getNextAvailableEntry(sub) == entry); - } - - - private void setLastSeenEntry(final Subscription sub, final QueueEntry entry) - { - QueueContext subContext = (QueueContext) sub.getQueueContext(); - if (subContext != null) - { - QueueEntry releasedEntry = subContext.getReleasedEntry(); - - QueueContext._lastSeenUpdater.set(subContext, entry); - if(releasedEntry == entry) - { - QueueContext._releasedUpdater.compareAndSet(subContext, releasedEntry, null); - } - } - } - - private void updateSubRequeueEntry(final Subscription sub, final QueueEntry entry) - { - - QueueContext subContext = (QueueContext) sub.getQueueContext(); - if(subContext != null) - { - QueueEntry oldEntry; - - while((oldEntry = subContext.getReleasedEntry()) == null || oldEntry.compareTo(entry) > 0) - { - if(QueueContext._releasedUpdater.compareAndSet(subContext, oldEntry, entry)) - { - break; - } - } - } - } - - public void requeue(QueueEntry entry) - { - SubscriptionList.SubscriptionNodeIterator subscriberIter = _subscriptionList.iterator(); - // iterate over all the subscribers, and if they are in advance of this queue entry then move them backwards - while (subscriberIter.advance() && entry.isAvailable()) - { - Subscription sub = subscriberIter.getNode().getSubscription(); - - // we don't make browsers send the same stuff twice - if (sub.seesRequeues()) - { - updateSubRequeueEntry(sub, entry); - } - } - - deliverAsync(); - - } - - public void dequeue(QueueEntry entry, Subscription sub) - { - decrementQueueCount(); - decrementQueueSize(entry); - if (entry.acquiredBySubscription()) - { - _deliveredMessages.decrementAndGet(); - } - - if(sub != null && sub.isSessionTransactional()) - { - incrementTxnDequeueStats(entry); - } - - checkCapacity(); - - } - - private void decrementQueueSize(final QueueEntry entry) - { - final ServerMessage message = entry.getMessage(); - long size = message.getSize(); - getAtomicQueueSize().addAndGet(-size); - _dequeueSize.addAndGet(size); - if(message.isPersistent() && isDurable()) - { - _persistentMessageDequeueSize.addAndGet(size); - _persistentMessageDequeueCount.incrementAndGet(); - } - } - - void decrementQueueCount() - { - getAtomicQueueCount().decrementAndGet(); - _dequeueCount.incrementAndGet(); - } - - public boolean resend(final QueueEntry entry, final Subscription subscription) throws AMQException - { - /* TODO : This is wrong as the subscription may be suspended, we should instead change the state of the message - entry to resend and move back the subscription pointer. */ - - subscription.getSendLock(); - try - { - if (!subscription.isClosed()) - { - deliverMessage(subscription, entry, false); - return true; - } - else - { - return false; - } - } - finally - { - subscription.releaseSendLock(); - } - } - - - - public int getConsumerCount() - { - return _subscriptionList.size(); - } - - public int getConsumerCountHigh() - { - return _counsumerCountHigh.get(); - } - - public int getActiveConsumerCount() - { - return _activeSubscriberCount.get(); - } - - public boolean isUnused() - { - return getConsumerCount() == 0; - } - - public boolean isEmpty() - { - return getMessageCount() == 0; - } - - public int getMessageCount() - { - return getAtomicQueueCount().get(); - } - - public long getQueueDepth() - { - return getAtomicQueueSize().get(); - } - - public int getUndeliveredMessageCount() - { - int count = getMessageCount() - _deliveredMessages.get(); - if (count < 0) - { - return 0; - } - else - { - return count; - } - } - - public long getReceivedMessageCount() - { - return _totalMessagesReceived.get(); - } - - public long getOldestMessageArrivalTime() - { - QueueEntry entry = getOldestQueueEntry(); - return entry == null ? Long.MAX_VALUE : entry.getMessage().getArrivalTime(); - } - - protected QueueEntry getOldestQueueEntry() - { - return _entries.next(_entries.getHead()); - } - - public boolean isDeleted() - { - return _deleted.get(); - } - - public List<QueueEntry> getMessagesOnTheQueue() - { - ArrayList<QueueEntry> entryList = new ArrayList<QueueEntry>(); - QueueEntryIterator queueListIterator = _entries.iterator(); - while (queueListIterator.advance()) - { - QueueEntry node = queueListIterator.getNode(); - if (node != null && !node.isDispensed()) - { - entryList.add(node); - } - } - return entryList; - - } - - public void stateChange(Subscription sub, Subscription.State oldState, Subscription.State newState) - { - if (oldState == Subscription.State.ACTIVE && newState != Subscription.State.ACTIVE) - { - _activeSubscriberCount.decrementAndGet(); - - } - else if (newState == Subscription.State.ACTIVE) - { - if (oldState != Subscription.State.ACTIVE) - { - _activeSubscriberCount.incrementAndGet(); - - } - deliverAsync(sub); - } - } - - public int compareTo(final AMQQueue o) - { - return _name.compareTo(o.getName()); - } - - public AtomicInteger getAtomicQueueCount() - { - return _atomicQueueCount; - } - - public AtomicLong getAtomicQueueSize() - { - return _atomicQueueSize; - } - - public boolean hasExclusiveSubscriber() - { - return _exclusiveSubscriber != null; - } - - private void setExclusiveSubscriber(Subscription exclusiveSubscriber) - { - _exclusiveSubscriber = exclusiveSubscriber; - } - - long getStateChangeCount() - { - return _stateChangeCount.get(); - } - - /** Used to track bindings to exchanges so that on deletion they can easily be cancelled. */ - protected QueueEntryList getEntries() - { - return _entries; - } - - protected SubscriptionList getSubscriptionList() - { - return _subscriptionList; - } - - - public static interface QueueEntryFilter - { - public boolean accept(QueueEntry entry); - - public boolean filterComplete(); - } - - - - public List<QueueEntry> getMessagesOnTheQueue(final long fromMessageId, final long toMessageId) - { - return getMessagesOnTheQueue(new QueueEntryFilter() - { - - public boolean accept(QueueEntry entry) - { - final long messageId = entry.getMessage().getMessageNumber(); - return messageId >= fromMessageId && messageId <= toMessageId; - } - - public boolean filterComplete() - { - return false; - } - }); - } - - public QueueEntry getMessageOnTheQueue(final long messageId) - { - List<QueueEntry> entries = getMessagesOnTheQueue(new QueueEntryFilter() - { - private boolean _complete; - - public boolean accept(QueueEntry entry) - { - _complete = entry.getMessage().getMessageNumber() == messageId; - return _complete; - } - - public boolean filterComplete() - { - return _complete; - } - }); - return entries.isEmpty() ? null : entries.get(0); - } - - public List<QueueEntry> getMessagesOnTheQueue(QueueEntryFilter filter) - { - ArrayList<QueueEntry> entryList = new ArrayList<QueueEntry>(); - QueueEntryIterator queueListIterator = _entries.iterator(); - while (queueListIterator.advance() && !filter.filterComplete()) - { - QueueEntry node = queueListIterator.getNode(); - if (!node.isDispensed() && filter.accept(node)) - { - entryList.add(node); - } - } - return entryList; - - } - - public void visit(final QueueEntryVisitor visitor) - { - QueueEntryIterator queueListIterator = _entries.iterator(); - - while(queueListIterator.advance()) - { - QueueEntry node = queueListIterator.getNode(); - - if(!node.isDispensed()) - { - if(visitor.visit(node)) - { - break; - } - } - } - } - - /** - * Returns a list of QueEntries from a given range of queue positions, eg messages 5 to 10 on the queue. - * - * The 'queue position' index starts from 1. Using 0 in 'from' will be ignored and continue from 1. - * Using 0 in the 'to' field will return an empty list regardless of the 'from' value. - * @param fromPosition - * @param toPosition - * @return - */ - public List<QueueEntry> getMessagesRangeOnTheQueue(final long fromPosition, final long toPosition) - { - return getMessagesOnTheQueue(new QueueEntryFilter() - { - private long position = 0; - - public boolean accept(QueueEntry entry) - { - position++; - return (position >= fromPosition) && (position <= toPosition); - } - - public boolean filterComplete() - { - return position >= toPosition; - } - }); - - } - - public void purge(final long request) throws AMQException - { - clear(request); - } - - public long getCreateTime() - { - return _createTime; - } - - // ------ Management functions - - // TODO - now only used by the tests - public void deleteMessageFromTop() - { - QueueEntryIterator queueListIterator = _entries.iterator(); - boolean noDeletes = true; - - while (noDeletes && queueListIterator.advance()) - { - QueueEntry node = queueListIterator.getNode(); - if (node.acquire()) - { - dequeueEntry(node); - noDeletes = false; - } - - } - } - - public long clearQueue() throws AMQException - { - return clear(0l); - } - - private long clear(final long request) throws AMQSecurityException - { - //Perform ACLs - if (!getVirtualHost().getSecurityManager().authorisePurge(this)) - { - throw new AMQSecurityException("Permission denied: queue " + getName()); - } - - QueueEntryIterator queueListIterator = _entries.iterator(); - long count = 0; - - ServerTransaction txn = new LocalTransaction(getVirtualHost().getMessageStore()); - - while (queueListIterator.advance()) - { - QueueEntry node = queueListIterator.getNode(); - if (node.acquire()) - { - dequeueEntry(node, txn); - if(++count == request) - { - break; - } - } - - } - - txn.commit(); - - return count; - } - - private void dequeueEntry(final QueueEntry node) - { - ServerTransaction txn = new AutoCommitTransaction(getVirtualHost().getMessageStore()); - dequeueEntry(node, txn); - } - - private void dequeueEntry(final QueueEntry node, ServerTransaction txn) - { - txn.dequeue(this, node.getMessage(), - new ServerTransaction.Action() - { - - public void postCommit() - { - node.discard(); - } - - public void onRollback() - { - - } - }); - } - - public void addQueueDeleteTask(final Task task) - { - _deleteTaskList.add(task); - } - - public void removeQueueDeleteTask(final Task task) - { - _deleteTaskList.remove(task); - } - - // TODO list all thrown exceptions - public int delete() throws AMQSecurityException, AMQException - { - // Check access - if (!_virtualHost.getSecurityManager().authoriseDelete(this)) - { - throw new AMQSecurityException("Permission denied: " + getName()); - } - - if (!_deleted.getAndSet(true)) - { - - for (Binding b : _bindings) - { - b.getExchange().removeBinding(b); - } - - SubscriptionList.SubscriptionNodeIterator subscriptionIter = _subscriptionList.iterator(); - - while (subscriptionIter.advance()) - { - Subscription s = subscriptionIter.getNode().getSubscription(); - if (s != null) - { - s.queueDeleted(this); - } - } - - - List<QueueEntry> entries = getMessagesOnTheQueue(new QueueEntryFilter() - { - - public boolean accept(QueueEntry entry) - { - return entry.acquire(); - } - - public boolean filterComplete() - { - return false; - } - }); - - ServerTransaction txn = new LocalTransaction(getVirtualHost().getMessageStore()); - - if(_alternateExchange != null) - { - - InboundMessageAdapter adapter = new InboundMessageAdapter(); - for(final QueueEntry entry : entries) - { - adapter.setEntry(entry); - List<? extends BaseQueue> queues = _alternateExchange.route(adapter); - if((queues == null || queues.size() == 0) && _alternateExchange.getAlternateExchange() != null) - { - queues = _alternateExchange.getAlternateExchange().route(adapter); - } - - final ServerMessage message = entry.getMessage(); - if(queues != null && queues.size() != 0) - { - final List<? extends BaseQueue> rerouteQueues = queues; - txn.enqueue(rerouteQueues, entry.getMessage(), - new ServerTransaction.Action() - { - - public void postCommit() - { - try - { - for(BaseQueue queue : rerouteQueues) - { - queue.enqueue(message); - } - } - catch (AMQException e) - { - throw new RuntimeException(e); - } - - } - - public void onRollback() - { - - } - }); - txn.dequeue(this, entry.getMessage(), - new ServerTransaction.Action() - { - - public void postCommit() - { - entry.discard(); - } - - public void onRollback() - { - } - }); - } - - } - - _alternateExchange.removeReference(this); - } - else - { - // TODO log discard - - for(final QueueEntry entry : entries) - { - final ServerMessage message = entry.getMessage(); - if(message != null) - { - txn.dequeue(this, message, - new ServerTransaction.Action() - { - - public void postCommit() - { - entry.discard(); - } - - public void onRollback() - { - } - }); - } - } - } - - txn.commit(); - - for (Task task : _deleteTaskList) - { - task.doTask(this); - } - - _deleteTaskList.clear(); - stop(); - - //Log Queue Deletion - CurrentActor.get().message(_logSubject, QueueMessages.DELETED()); - - } - return getMessageCount(); - - } - - public void stop() - { - if (!_stopped.getAndSet(true)) - { - ReferenceCountingExecutorService.getInstance().releaseExecutorService(); - } - } - - public void checkCapacity(AMQSessionModel channel) - { - if(_capacity != 0l) - { - if(_atomicQueueSize.get() > _capacity) - { - _overfull.set(true); - //Overfull log message - _logActor.message(_logSubject, QueueMessages.OVERFULL(_atomicQueueSize.get(), _capacity)); - - _blockedChannels.add(channel); - - channel.block(this); - - if(_atomicQueueSize.get() <= _flowResumeCapacity) - { - - //Underfull log message - _logActor.message(_logSubject, QueueMessages.UNDERFULL(_atomicQueueSize.get(), _flowResumeCapacity)); - - channel.unblock(this); - _blockedChannels.remove(channel); - - } - - } - - - - } - } - - private void checkCapacity() - { - if(_capacity != 0L) - { - if(_overfull.get() && _atomicQueueSize.get() <= _flowResumeCapacity) - { - if(_overfull.compareAndSet(true,false)) - {//Underfull log message - _logActor.message(_logSubject, QueueMessages.UNDERFULL(_atomicQueueSize.get(), _flowResumeCapacity)); - } - - for(final AMQSessionModel blockedChannel : _blockedChannels) - { - blockedChannel.unblock(this); - _blockedChannels.remove(blockedChannel); - } - } - } - } - - private QueueRunner _queueRunner = new QueueRunner(this); - - public void deliverAsync() - { - _stateChangeCount.incrementAndGet(); - - _queueRunner.execute(_asyncDelivery); - - } - - public void deliverAsync(Subscription sub) - { - if(_exclusiveSubscriber == null) - { - deliverAsync(); - } - else - { - SubFlushRunner flusher = (SubFlushRunner) sub.get(SUB_FLUSH_RUNNER); - if(flusher == null) - { - flusher = new SubFlushRunner(sub); - sub.set(SUB_FLUSH_RUNNER, flusher); - } - flusher.execute(_asyncDelivery); - } - - } - - public void flushSubscription(Subscription sub) throws AMQException - { - // Access control - if (!getVirtualHost().getSecurityManager().authoriseConsume(this)) - { - throw new AMQSecurityException("Permission denied: " + getName()); - } - flushSubscription(sub, Long.MAX_VALUE); - } - - public boolean flushSubscription(Subscription sub, long iterations) throws AMQException - { - boolean atTail = false; - final boolean keepSendLockHeld = iterations <= SimpleAMQQueue.MAX_ASYNC_DELIVERIES; - boolean queueEmpty = false; - - try - { - if(keepSendLockHeld) - { - sub.getSendLock(); - } - while (!sub.isSuspended() && !atTail && iterations != 0) - { - try - { - if(!keepSendLockHeld) - { - sub.getSendLock(); - } - - atTail = attemptDelivery(sub, true); - if (atTail && getNextAvailableEntry(sub) == null) - { - queueEmpty = true; - } - else if (!atTail) - { - iterations--; - } - } - finally - { - if(!keepSendLockHeld) - { - sub.releaseSendLock(); - } - } - } - } - finally - { - if(keepSendLockHeld) - { - sub.releaseSendLock(); - } - if(queueEmpty) - { - sub.queueEmpty(); - } - - sub.flushBatched(); - - } - - - // if there's (potentially) more than one subscription the others will potentially not have been advanced to the - // next entry they are interested in yet. This would lead to holding on to references to expired messages, etc - // which would give us memory "leak". - - if (!hasExclusiveSubscriber()) - { - advanceAllSubscriptions(); - } - return atTail; - } - - /** - * Attempt delivery for the given subscription. - * - * Looks up the next node for the subscription and attempts to deliver it. - * - * - * @param sub - * @param batch - * @return true if we have completed all possible deliveries for this sub. - * @throws AMQException - */ - private boolean attemptDelivery(Subscription sub, boolean batch) throws AMQException - { - boolean atTail = false; - - boolean subActive = sub.isActive() && !sub.isSuspended(); - if (subActive) - { - - QueueEntry node = getNextAvailableEntry(sub); - - if (node != null && node.isAvailable()) - { - if (sub.hasInterest(node) && mightAssign(sub, node)) - { - if (!sub.wouldSuspend(node)) - { - if (sub.acquires() && !(assign(sub, node) && node.acquire(sub))) - { - // restore credit here that would have been taken away by wouldSuspend since we didn't manage - // to acquire the entry for this subscription - sub.restoreCredit(node); - } - else - { - deliverMessage(sub, node, batch); - } - - } - else // Not enough Credit for message and wouldSuspend - { - //QPID-1187 - Treat the subscription as suspended for this message - // and wait for the message to be removed to continue delivery. - subActive = false; - node.addStateChangeListener(new QueueEntryListener(sub)); - } - } - - } - atTail = (node == null) || (_entries.next(node) == null); - } - return atTail || !subActive; - } - - protected void advanceAllSubscriptions() throws AMQException - { - SubscriptionList.SubscriptionNodeIterator subscriberIter = _subscriptionList.iterator(); - while (subscriberIter.advance()) - { - SubscriptionList.SubscriptionNode subNode = subscriberIter.getNode(); - Subscription sub = subNode.getSubscription(); - if(sub.acquires()) - { - getNextAvailableEntry(sub); - } - else - { - // TODO - } - } - } - - private QueueEntry getNextAvailableEntry(final Subscription sub) - throws AMQException - { - QueueContext context = (QueueContext) sub.getQueueContext(); - if(context != null) - { - QueueEntry lastSeen = context.getLastSeenEntry(); - QueueEntry releasedNode = context.getReleasedEntry(); - - QueueEntry node = (releasedNode != null && lastSeen.compareTo(releasedNode)>=0) ? releasedNode : _entries.next(lastSeen); - - boolean expired = false; - while (node != null && (!node.isAvailable() || (expired = node.expired()) || !sub.hasInterest(node) || - !mightAssign(sub,node))) - { - if (expired) - { - expired = false; - if (node.acquire()) - { - dequeueEntry(node); - } - } - - if(QueueContext._lastSeenUpdater.compareAndSet(context, lastSeen, node)) - { - QueueContext._releasedUpdater.compareAndSet(context, releasedNode, null); - } - - lastSeen = context.getLastSeenEntry(); - releasedNode = context.getReleasedEntry(); - node = (releasedNode != null && lastSeen.compareTo(releasedNode)>0) ? releasedNode : _entries.next(lastSeen); - } - return node; - } - else - { - return null; - } - } - - public boolean isEntryAheadOfSubscription(QueueEntry entry, Subscription sub) - { - QueueContext context = (QueueContext) sub.getQueueContext(); - if(context != null) - { - QueueEntry releasedNode = context.getReleasedEntry(); - return releasedNode != null && releasedNode.compareTo(entry) < 0; - } - else - { - return false; - } - } - - /** - * Used by queue Runners to asynchronously deliver messages to consumers. - * - * A queue Runner is started whenever a state change occurs, e.g when a new - * message arrives on the queue and cannot be immediately delivered to a - * subscription (i.e. asynchronous delivery is required). Unless there are - * SubFlushRunners operating (due to subscriptions unsuspending) which are - * capable of accepting/delivering all messages then these messages would - * otherwise remain on the queue. - * - * processQueue should be running while there are messages on the queue AND - * there are subscriptions that can deliver them. If there are no - * subscriptions capable of delivering the remaining messages on the queue - * then processQueue should stop to prevent spinning. - * - * Since processQueue is runs in a fixed size Executor, it should not run - * indefinitely to prevent starving other tasks of CPU (e.g jobs to process - * incoming messages may not be able to be scheduled in the thread pool - * because all threads are working on clearing down large queues). To solve - * this problem, after an arbitrary number of message deliveries the - * processQueue job stops iterating, resubmits itself to the executor, and - * ends the current instance - * - * @param runner the Runner to schedule - * @throws AMQException - */ - public long processQueue(QueueRunner runner) throws AMQException - { - long stateChangeCount = Long.MIN_VALUE; - long previousStateChangeCount = Long.MIN_VALUE; - long rVal = Long.MIN_VALUE; - boolean deliveryIncomplete = true; - - boolean lastLoop = false; - int iterations = MAX_ASYNC_DELIVERIES; - - final int numSubs = _subscriptionList.size(); - - final int perSub = Math.max(iterations / Math.max(numSubs,1), 1); - - // For every message enqueue/requeue the we fire deliveryAsync() which - // increases _stateChangeCount. If _sCC changes whilst we are in our loop - // (detected by setting previousStateChangeCount to stateChangeCount in the loop body) - // then we will continue to run for a maximum of iterations. - // So whilst delivery/rejection is going on a processQueue thread will be running - while (iterations != 0 && ((previousStateChangeCount != (stateChangeCount = _stateChangeCount.get())) || deliveryIncomplete)) - { - // we want to have one extra loop after every subscription has reached the point where it cannot move - // further, just in case the advance of one subscription in the last loop allows a different subscription to - // move forward in the next iteration - - if (previousStateChangeCount != stateChangeCount) - { - //further asynchronous delivery is required since the - //previous loop. keep going if iteration slicing allows. - lastLoop = false; - rVal = stateChangeCount; - } - - previousStateChangeCount = stateChangeCount; - boolean allSubscriptionsDone = true; - boolean subscriptionDone; - - SubscriptionList.SubscriptionNodeIterator subscriptionIter = _subscriptionList.iterator(); - //iterate over the subscribers and try to advance their pointer - while (subscriptionIter.advance()) - { - Subscription sub = subscriptionIter.getNode().getSubscription(); - sub.getSendLock(); - - try - { - for(int i = 0 ; i < perSub; i++) - { - //attempt delivery. returns true if no further delivery currently possible to this sub - subscriptionDone = attemptDelivery(sub, true); - if (subscriptionDone) - { - sub.flushBatched(); - if (lastLoop && !sub.isSuspended()) - { - sub.queueEmpty(); - } - break; - } - else - { - //this subscription can accept additional deliveries, so we must - //keep going after this (if iteration slicing allows it) - allSubscriptionsDone = false; - lastLoop = false; - if(--iterations == 0) - { - sub.flushBatched(); - break; - } - } - - } - - sub.flushBatched(); - } - finally - { - sub.releaseSendLock(); - } - } - - if(allSubscriptionsDone && lastLoop) - { - //We have done an extra loop already and there are again - //again no further delivery attempts possible, only - //keep going if state change demands it. - deliveryIncomplete = false; - } - else if(allSubscriptionsDone) - { - //All subscriptions reported being done, but we have to do - //an extra loop if the iterations are not exhausted and - //there is still any work to be done - deliveryIncomplete = _subscriptionList.size() != 0; - lastLoop = true; - } - else - { - //some subscriptions can still accept more messages, - //keep going if iteration count allows. - lastLoop = false; - deliveryIncomplete = true; - } - - } - - // If iterations == 0 then the limiting factor was the time-slicing rather than available messages or credit - // therefore we should schedule this runner again (unless someone beats us to it :-) ). - if (iterations == 0) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Rescheduling runner:" + runner); - } - return 0L; - } - return rVal; - - } - - public void checkMessageStatus() throws AMQException - { - QueueEntryIterator queueListIterator = _entries.iterator(); - - while (queueListIterator.advance()) - { - QueueEntry node = queueListIterator.getNode(); - // Only process nodes that are not currently deleted and not dequeued - if (!node.isDispensed()) - { - // If the node has exired then acquire it - if (node.expired() && node.acquire()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Dequeuing expired node " + node); - } - // Then dequeue it. - dequeueEntry(node); - } - else - { - // There is a chance that the node could be deleted by - // the time the check actually occurs. So verify we - // can actually get the message to perform the check. - ServerMessage msg = node.getMessage(); - if (msg != null) - { - checkForNotification(msg); - } - } - } - } - - } - - public long getMinimumAlertRepeatGap() - { - return _minimumAlertRepeatGap; - } - - public void setMinimumAlertRepeatGap(long minimumAlertRepeatGap) - { - _minimumAlertRepeatGap = minimumAlertRepeatGap; - } - - public long getMaximumMessageAge() - { - return _maximumMessageAge; - } - - public void setMaximumMessageAge(long maximumMessageAge) - { - _maximumMessageAge = maximumMessageAge; - if (maximumMessageAge == 0L) - { - _notificationChecks.remove(NotificationCheck.MESSAGE_AGE_ALERT); - } - else - { - _notificationChecks.add(NotificationCheck.MESSAGE_AGE_ALERT); - } - } - - public long getMaximumMessageCount() - { - return _maximumMessageCount; - } - - public void setMaximumMessageCount(final long maximumMessageCount) - { - _maximumMessageCount = maximumMessageCount; - if (maximumMessageCount == 0L) - { - _notificationChecks.remove(NotificationCheck.MESSAGE_COUNT_ALERT); - } - else - { - _notificationChecks.add(NotificationCheck.MESSAGE_COUNT_ALERT); - } - - } - - public long getMaximumQueueDepth() - { - return _maximumQueueDepth; - } - - // Sets the queue depth, the max queue size - public void setMaximumQueueDepth(final long maximumQueueDepth) - { - _maximumQueueDepth = maximumQueueDepth; - if (maximumQueueDepth == 0L) - { - _notificationChecks.remove(NotificationCheck.QUEUE_DEPTH_ALERT); - } - else - { - _notificationChecks.add(NotificationCheck.QUEUE_DEPTH_ALERT); - } - - } - - public long getMaximumMessageSize() - { - return _maximumMessageSize; - } - - public void setMaximumMessageSize(final long maximumMessageSize) - { - _maximumMessageSize = maximumMessageSize; - if (maximumMessageSize == 0L) - { - _notificationChecks.remove(NotificationCheck.MESSAGE_SIZE_ALERT); - } - else - { - _notificationChecks.add(NotificationCheck.MESSAGE_SIZE_ALERT); - } - } - - public long getCapacity() - { - return _capacity; - } - - public void setCapacity(long capacity) - { - _capacity = capacity; - } - - public long getFlowResumeCapacity() - { - return _flowResumeCapacity; - } - - public void setFlowResumeCapacity(long flowResumeCapacity) - { - _flowResumeCapacity = flowResumeCapacity; - - checkCapacity(); - } - - public boolean isOverfull() - { - return _overfull.get(); - } - - public Set<NotificationCheck> getNotificationChecks() - { - return _notificationChecks; - } - - private final class QueueEntryListener implements QueueEntry.StateChangeListener - { - - private final Subscription _sub; - - public QueueEntryListener(final Subscription sub) - { - _sub = sub; - } - - public boolean equals(Object o) - { - return o instanceof SimpleAMQQueue.QueueEntryListener - && _sub == ((QueueEntryListener) o)._sub; - } - - public int hashCode() - { - return System.identityHashCode(_sub); - } - - public void stateChanged(QueueEntry entry, QueueEntry.State oldSate, QueueEntry.State newState) - { - entry.removeStateChangeListener(this); - deliverAsync(_sub); - } - } - - public List<Long> getMessagesOnTheQueue(int num) - { - return getMessagesOnTheQueue(num, 0); - } - - public List<Long> getMessagesOnTheQueue(int num, int offset) - { - ArrayList<Long> ids = new ArrayList<Long>(num); - QueueEntryIterator it = _entries.iterator(); - for (int i = 0; i < offset; i++) - { - it.advance(); - } - - for (int i = 0; i < num && !it.atTail(); i++) - { - it.advance(); - ids.add(it.getNode().getMessage().getMessageNumber()); - } - return ids; - } - - public AMQSessionModel getExclusiveOwningSession() - { - return _exclusiveOwner; - } - - public void setExclusiveOwningSession(AMQSessionModel exclusiveOwner) - { - _exclusive = true; - _exclusiveOwner = exclusiveOwner; - } - - - public void configure(QueueConfiguration config) - { - if (config != null) - { - setMaximumMessageAge(config.getMaximumMessageAge()); - setMaximumQueueDepth(config.getMaximumQueueDepth()); - setMaximumMessageSize(config.getMaximumMessageSize()); - setMaximumMessageCount(config.getMaximumMessageCount()); - setMinimumAlertRepeatGap(config.getMinimumAlertRepeatGap()); - setMaximumDeliveryCount(config.getMaxDeliveryCount()); - _capacity = config.getCapacity(); - _flowResumeCapacity = config.getFlowResumeCapacity(); - } - } - - public long getMessageDequeueCount() - { - return _dequeueCount.get(); - } - - public long getTotalEnqueueSize() - { - return _enqueueSize.get(); - } - - public long getTotalDequeueSize() - { - return _dequeueSize.get(); - } - - public long getByteTxnEnqueues() - { - return _byteTxnEnqueues.get(); - } - - public long getByteTxnDequeues() - { - return _byteTxnDequeues.get(); - } - - public long getMsgTxnEnqueues() - { - return _msgTxnEnqueues.get(); - } - - public long getMsgTxnDequeues() - { - return _msgTxnDequeues.get(); - } - - public long getPersistentByteEnqueues() - { - return _persistentMessageEnqueueSize.get(); - } - - public long getPersistentByteDequeues() - { - return _persistentMessageDequeueSize.get(); - } - - public long getPersistentMsgEnqueues() - { - return _persistentMessageEnqueueCount.get(); - } - - public long getPersistentMsgDequeues() - { - return _persistentMessageDequeueCount.get(); - } - - - @Override - public String toString() - { - return getName(); - } - - public long getUnackedMessageCountHigh() - { - return _unackedMsgCountHigh.get(); - } - - public long getUnackedMessageCount() - { - return _unackedMsgCount.get(); - } - - public long getUnackedMessageBytes() - { - return _unackedMsgBytes.get(); - } - - public void decrementUnackedMsgCount(QueueEntry queueEntry) - { - _unackedMsgCount.decrementAndGet(); - _unackedMsgBytes.addAndGet(-queueEntry.getSize()); - } - - private void incrementUnackedMsgCount(QueueEntry entry) - { - long unackedMsgCount = _unackedMsgCount.incrementAndGet(); - _unackedMsgBytes.addAndGet(entry.getSize()); - - long unackedMsgCountHigh; - while(unackedMsgCount > (unackedMsgCountHigh = _unackedMsgCountHigh.get())) - { - if(_unackedMsgCountHigh.compareAndSet(unackedMsgCountHigh, unackedMsgCount)) - { - break; - } - } - } - - public LogActor getLogActor() - { - return _logActor; - } - - public int getMaximumDeliveryCount() - { - return _maximumDeliveryCount; - } - - public void setMaximumDeliveryCount(final int maximumDeliveryCount) - { - _maximumDeliveryCount = maximumDeliveryCount; - } - - /** - * Checks if there is any notification to send to the listeners - */ - private void checkForNotification(ServerMessage<?> msg) throws AMQException - { - final Set<NotificationCheck> notificationChecks = getNotificationChecks(); - final AMQQueue.NotificationListener listener = _notificationListener; - - if(listener != null && !notificationChecks.isEmpty()) - { - final long currentTime = System.currentTimeMillis(); - final long thresholdTime = currentTime - getMinimumAlertRepeatGap(); - - for (NotificationCheck check : notificationChecks) - { - if (check.isMessageSpecific() || (_lastNotificationTimes[check.ordinal()] < thresholdTime)) - { - if (check.notifyIfNecessary(msg, this, listener)) - { - _lastNotificationTimes[check.ordinal()] = currentTime; - } - } - } - } - } - - public void setNotificationListener(AMQQueue.NotificationListener listener) - { - _notificationListener = listener; - } - - @Override - public void setDescription(String description) - { - if (description == null) - { - _arguments.remove(Queue.DESCRIPTION); - } - else - { - _arguments.put(Queue.DESCRIPTION, description); - } - } - - @Override - public String getDescription() - { - return (String) _arguments.get(Queue.DESCRIPTION); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryImpl.java deleted file mode 100644 index 4a10d31d37..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.server.message.ServerMessage; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -public class SimpleQueueEntryImpl extends QueueEntryImpl -{ - static final AtomicReferenceFieldUpdater<SimpleQueueEntryImpl, SimpleQueueEntryImpl> - _nextUpdater = - AtomicReferenceFieldUpdater.newUpdater - (SimpleQueueEntryImpl.class, SimpleQueueEntryImpl.class, "_next"); - - private volatile SimpleQueueEntryImpl _next; - - public SimpleQueueEntryImpl(SimpleQueueEntryList queueEntryList) - { - super(queueEntryList); - } - - public SimpleQueueEntryImpl(SimpleQueueEntryList queueEntryList, ServerMessage message, final long entryId) - { - super(queueEntryList, message, entryId); - } - - public SimpleQueueEntryImpl(SimpleQueueEntryList queueEntryList, ServerMessage message) - { - super(queueEntryList, message); - } - - public SimpleQueueEntryImpl getNextNode() - { - return _next; - } - - public SimpleQueueEntryImpl getNextValidEntry() - { - - SimpleQueueEntryImpl next = getNextNode(); - while(next != null && next.isDispensed()) - { - - final SimpleQueueEntryImpl newNext = next.getNextNode(); - if(newNext != null) - { - SimpleQueueEntryList._nextUpdater.compareAndSet(this,next, newNext); - next = getNextNode(); - } - else - { - next = null; - } - - } - return next; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java deleted file mode 100644 index b8d8ec19f4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java +++ /dev/null @@ -1,205 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.queue; - -import org.apache.qpid.server.message.ServerMessage; - -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -public class SimpleQueueEntryList implements QueueEntryList<SimpleQueueEntryImpl> -{ - - private final SimpleQueueEntryImpl _head; - - private volatile SimpleQueueEntryImpl _tail; - - static final AtomicReferenceFieldUpdater<SimpleQueueEntryList, SimpleQueueEntryImpl> - _tailUpdater = - AtomicReferenceFieldUpdater.newUpdater - (SimpleQueueEntryList.class, SimpleQueueEntryImpl.class, "_tail"); - - - private final AMQQueue _queue; - - static final AtomicReferenceFieldUpdater<SimpleQueueEntryImpl, SimpleQueueEntryImpl> - _nextUpdater = SimpleQueueEntryImpl._nextUpdater; - - private AtomicLong _scavenges = new AtomicLong(0L); - private final long _scavengeCount = Integer.getInteger("qpid.queue.scavenge_count", 50); - private final AtomicReference<SimpleQueueEntryImpl> _unscavengedHWM = new AtomicReference<SimpleQueueEntryImpl>(); - - - public SimpleQueueEntryList(AMQQueue queue) - { - _queue = queue; - _head = new SimpleQueueEntryImpl(this); - _tail = _head; - } - - void scavenge() - { - SimpleQueueEntryImpl hwm = _unscavengedHWM.getAndSet(null); - SimpleQueueEntryImpl next = _head.getNextValidEntry(); - - if(hwm != null) - { - while (next != null && hwm.compareTo(next)>0) - { - next = next.getNextValidEntry(); - } - } - } - - - public AMQQueue getQueue() - { - return _queue; - } - - - public SimpleQueueEntryImpl add(ServerMessage message) - { - SimpleQueueEntryImpl node = createQueueEntry(message); - for (;;) - { - SimpleQueueEntryImpl tail = _tail; - SimpleQueueEntryImpl next = tail.getNextNode(); - if (tail == _tail) - { - if (next == null) - { - node.setEntryId(tail.getEntryId()+1); - if (_nextUpdater.compareAndSet(tail, null, node)) - { - _tailUpdater.compareAndSet(this, tail, node); - - return node; - } - } - else - { - _tailUpdater.compareAndSet(this,tail, next); - } - } - } - } - - protected SimpleQueueEntryImpl createQueueEntry(ServerMessage<?> message) - { - return new SimpleQueueEntryImpl(this, message); - } - - public SimpleQueueEntryImpl next(SimpleQueueEntryImpl node) - { - return node.getNextValidEntry(); - } - - public static class QueueEntryIteratorImpl implements QueueEntryIterator<SimpleQueueEntryImpl> - { - private SimpleQueueEntryImpl _lastNode; - - QueueEntryIteratorImpl(SimpleQueueEntryImpl startNode) - { - _lastNode = startNode; - } - - public boolean atTail() - { - return _lastNode.getNextValidEntry() == null; - } - - public SimpleQueueEntryImpl getNode() - { - return _lastNode; - } - - public boolean advance() - { - SimpleQueueEntryImpl nextValidNode = _lastNode.getNextValidEntry(); - - if(nextValidNode != null) - { - _lastNode = nextValidNode; - } - - return nextValidNode != null; - } - } - - public QueueEntryIteratorImpl iterator() - { - return new QueueEntryIteratorImpl(_head); - } - - - public SimpleQueueEntryImpl getHead() - { - return _head; - } - - public void entryDeleted(SimpleQueueEntryImpl queueEntry) - { - SimpleQueueEntryImpl next = _head.getNextNode(); - SimpleQueueEntryImpl newNext = _head.getNextValidEntry(); - - // the head of the queue has not been deleted, hence the deletion must have been mid queue. - if (next == newNext) - { - SimpleQueueEntryImpl unscavengedHWM = _unscavengedHWM.get(); - while(unscavengedHWM == null || unscavengedHWM.compareTo(queueEntry)<0) - { - _unscavengedHWM.compareAndSet(unscavengedHWM, queueEntry); - unscavengedHWM = _unscavengedHWM.get(); - } - if (_scavenges.incrementAndGet() > _scavengeCount) - { - _scavenges.set(0L); - scavenge(); - } - } - else - { - SimpleQueueEntryImpl unscavengedHWM = _unscavengedHWM.get(); - if(unscavengedHWM != null && (next == null || unscavengedHWM.compareTo(next) < 0)) - { - _unscavengedHWM.compareAndSet(unscavengedHWM, null); - } - } - } - - public int getPriorities() - { - return 0; - } - - static class Factory implements QueueEntryListFactory - { - - public SimpleQueueEntryList createQueueEntryList(AMQQueue queue) - { - return new SimpleQueueEntryList(queue); - } - } - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueue.java deleted file mode 100644 index b3566df0c4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueue.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.Map; -import java.util.UUID; - -public class SortedQueue extends OutOfOrderQueue -{ - //Lock object to synchronize enqueue. Used instead of the object - //monitor to prevent lock order issues with subscription sendLocks - //and consumer updates in the super classes - private final Object _sortedQueueLock = new Object(); - private final String _sortedPropertyName; - - protected SortedQueue(UUID id, final String name, - final boolean durable, final String owner, final boolean autoDelete, - final boolean exclusive, final VirtualHost virtualHost, Map<String, Object> arguments, String sortedPropertyName) - { - super(id, name, durable, owner, autoDelete, exclusive, - virtualHost, new SortedQueueEntryListFactory(sortedPropertyName), arguments); - this._sortedPropertyName = sortedPropertyName; - } - - public String getSortedPropertyName() - { - return _sortedPropertyName; - } - - public void enqueue(ServerMessage message, PostEnqueueAction action) throws AMQException - { - synchronized (_sortedQueueLock) - { - super.enqueue(message, action); - } - } -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryImpl.java deleted file mode 100644 index 1052adbe67..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryImpl.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.server.message.ServerMessage; - -/** - * An implementation of QueueEntryImpl to be used in SortedQueueEntryList. - */ -public class SortedQueueEntryImpl extends QueueEntryImpl -{ - public static enum Colour - { - RED, BLACK - }; - - private volatile SortedQueueEntryImpl _next; - private SortedQueueEntryImpl _prev; - private String _key; - - private Colour _colour = Colour.BLACK; - private SortedQueueEntryImpl _parent; - private SortedQueueEntryImpl _left; - private SortedQueueEntryImpl _right; - - public SortedQueueEntryImpl(final SortedQueueEntryList queueEntryList) - { - super(queueEntryList); - } - - public SortedQueueEntryImpl(final SortedQueueEntryList queueEntryList, - final ServerMessage message, final long entryId) - { - super(queueEntryList, message, entryId); - } - - @Override - public int compareTo(final QueueEntry o) - { - final String otherKey = ((SortedQueueEntryImpl) o)._key; - final int compare = _key == null ? (otherKey == null ? 0 : -1) : otherKey == null ? 1 : _key.compareTo(otherKey); - return compare == 0 ? super.compareTo(o) : compare; - } - - public Colour getColour() - { - return _colour; - } - - public String getKey() - { - return _key; - } - - public SortedQueueEntryImpl getLeft() - { - return _left; - } - - public SortedQueueEntryImpl getNextNode() - { - return _next; - } - - @Override - public SortedQueueEntryImpl getNextValidEntry() - { - return getNextNode(); - } - - public SortedQueueEntryImpl getParent() - { - return _parent; - } - - public SortedQueueEntryImpl getPrev() - { - return _prev; - } - - public SortedQueueEntryImpl getRight() - { - return _right; - } - - public void setColour(final Colour colour) - { - _colour = colour; - } - - public void setKey(final String key) - { - _key = key; - } - - public void setLeft(final SortedQueueEntryImpl left) - { - _left = left; - } - - public void setNext(final SortedQueueEntryImpl next) - { - _next = next; - } - - public void setParent(final SortedQueueEntryImpl parent) - { - _parent = parent; - } - - public void setPrev(final SortedQueueEntryImpl prev) - { - _prev = prev; - } - - public void setRight(final SortedQueueEntryImpl right) - { - _right = right; - } - - @Override - public String toString() - { - return "(" + (_colour == Colour.RED ? "Red," : "Black,") + _key + ")"; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryList.java deleted file mode 100644 index 7f742d455d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryList.java +++ /dev/null @@ -1,659 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.queue.SortedQueueEntryImpl.Colour; - -/** - * A sorted implementation of QueueEntryList. - * Uses the red/black tree algorithm specified in "Introduction to Algorithms". - * ISBN-10: 0262033844 - * ISBN-13: 978-0262033848 - * @see http://en.wikipedia.org/wiki/Red-black_tree - */ -public class SortedQueueEntryList implements QueueEntryList<SortedQueueEntryImpl> -{ - private final SortedQueueEntryImpl _head; - private SortedQueueEntryImpl _root; - private long _entryId = Long.MIN_VALUE; - private final Object _lock = new Object(); - private final AMQQueue _queue; - private final String _propertyName; - - public SortedQueueEntryList(final AMQQueue queue, final String propertyName) - { - _queue = queue; - _head = new SortedQueueEntryImpl(this); - _propertyName = propertyName; - } - - public AMQQueue getQueue() - { - return _queue; - } - - public SortedQueueEntryImpl add(final ServerMessage message) - { - synchronized(_lock) - { - String key = null; - final Object val = message.getMessageHeader().getHeader(_propertyName); - if(val != null) - { - key = val.toString(); - } - - final SortedQueueEntryImpl entry = new SortedQueueEntryImpl(this,message, ++_entryId); - entry.setKey(key); - - insert(entry); - - return entry; - } - } - - /** - * Red Black Tree insert implementation. - * @param entry the entry to insert. - */ - private void insert(final SortedQueueEntryImpl entry) - { - SortedQueueEntryImpl node = _root; - if((node = _root) == null) - { - _root = entry; - _head.setNext(entry); - entry.setPrev(_head); - return; - } - else - { - SortedQueueEntryImpl parent = null; - while(node != null) - { - parent = node; - if(entry.compareTo(node) < 0) - { - node = node.getLeft(); - } - else - { - node = node.getRight(); - } - } - entry.setParent(parent); - - if(entry.compareTo(parent) < 0) - { - parent.setLeft(entry); - final SortedQueueEntryImpl prev = parent.getPrev(); - entry.setNext(parent); - prev.setNext(entry); - entry.setPrev(prev); - parent.setPrev(entry); - } - else - { - parent.setRight(entry); - - final SortedQueueEntryImpl next = parent.getNextValidEntry(); - entry.setNext(next); - parent.setNext(entry); - - if(next != null) - { - next.setPrev(entry); - } - entry.setPrev(parent); - } - } - entry.setColour(Colour.RED); - insertFixup(entry); - } - - private void insertFixup(SortedQueueEntryImpl entry) - { - while(isParentColour(entry, Colour.RED)) - { - final SortedQueueEntryImpl grandparent = nodeGrandparent(entry); - - if(nodeParent(entry) == leftChild(grandparent)) - { - final SortedQueueEntryImpl y = rightChild(grandparent); - if(isNodeColour(y, Colour.RED)) - { - setColour(nodeParent(entry), Colour.BLACK); - setColour(y, Colour.BLACK); - setColour(grandparent, Colour.RED); - entry = grandparent; - } - else - { - if(entry == rightChild(nodeParent(entry))) - { - entry = nodeParent(entry); - leftRotate(entry); - } - setColour(nodeParent(entry), Colour.BLACK); - setColour(nodeGrandparent(entry), Colour.RED); - rightRotate(nodeGrandparent(entry)); - } - } - else - { - final SortedQueueEntryImpl y = leftChild(grandparent); - if(isNodeColour(y, Colour.RED)) - { - setColour(nodeParent(entry), Colour.BLACK); - setColour(y, Colour.BLACK); - setColour(grandparent, Colour.RED); - entry = grandparent; - } - else - { - if(entry == leftChild(nodeParent(entry))) - { - entry = nodeParent(entry); - rightRotate(entry); - } - setColour(nodeParent(entry), Colour.BLACK); - setColour(nodeGrandparent(entry), Colour.RED); - leftRotate(nodeGrandparent(entry)); - } - } - } - _root.setColour(Colour.BLACK); - } - - private void leftRotate(final SortedQueueEntryImpl entry) - { - if(entry != null) - { - final SortedQueueEntryImpl rightChild = rightChild(entry); - entry.setRight(rightChild.getLeft()); - if(entry.getRight() != null) - { - entry.getRight().setParent(entry); - } - rightChild.setParent(entry.getParent()); - if(entry.getParent() == null) - { - _root = rightChild; - } - else if(entry == entry.getParent().getLeft()) - { - entry.getParent().setLeft(rightChild); - } - else - { - entry.getParent().setRight(rightChild); - } - rightChild.setLeft(entry); - entry.setParent(rightChild); - } - } - - private void rightRotate(final SortedQueueEntryImpl entry) - { - if(entry != null) - { - final SortedQueueEntryImpl leftChild = leftChild(entry); - entry.setLeft(leftChild.getRight()); - if(entry.getLeft() != null) - { - leftChild.getRight().setParent(entry); - } - leftChild.setParent(entry.getParent()); - if(leftChild.getParent() == null) - { - _root = leftChild; - } - else if(entry == entry.getParent().getRight()) - { - entry.getParent().setRight(leftChild); - } - else - { - entry.getParent().setLeft(leftChild); - } - leftChild.setRight(entry); - entry.setParent(leftChild); - } - } - - private void setColour(final SortedQueueEntryImpl node, final Colour colour) - { - if(node != null) - { - node.setColour(colour); - } - } - - private SortedQueueEntryImpl leftChild(final SortedQueueEntryImpl node) - { - return node == null ? null : node.getLeft(); - } - - private SortedQueueEntryImpl rightChild(final SortedQueueEntryImpl node) - { - return node == null ? null : node.getRight(); - } - - private SortedQueueEntryImpl nodeParent(final SortedQueueEntryImpl node) - { - return node == null ? null : node.getParent(); - } - - private SortedQueueEntryImpl nodeGrandparent(final SortedQueueEntryImpl node) - { - return nodeParent(nodeParent(node)); - } - - private boolean isParentColour(final SortedQueueEntryImpl node, final SortedQueueEntryImpl.Colour colour) - { - - return node != null && isNodeColour(node.getParent(), colour); - } - - protected boolean isNodeColour(final SortedQueueEntryImpl node, final SortedQueueEntryImpl.Colour colour) - { - return (node == null ? Colour.BLACK : node.getColour()) == colour; - } - - public SortedQueueEntryImpl next(final SortedQueueEntryImpl node) - { - synchronized(_lock) - { - if(node.isDispensed() && _head != node) - { - SortedQueueEntryImpl current = _head; - SortedQueueEntryImpl next; - while(current != null) - { - next = current.getNextValidEntry(); - if(current.compareTo(node)>0 && !current.isDispensed()) - { - break; - } - else - { - current = next; - } - } - return current; - } - else - { - return node.getNextValidEntry(); - } - } - } - - public QueueEntryIterator<SortedQueueEntryImpl> iterator() - { - return new QueueEntryIteratorImpl(_head); - } - - public SortedQueueEntryImpl getHead() - { - return _head; - } - - protected SortedQueueEntryImpl getRoot() - { - return _root; - } - - public void entryDeleted(final SortedQueueEntryImpl entry) - { - synchronized(_lock) - { - // If the node to be removed has two children, we swap the position - // of the node and its successor in the tree - if(leftChild(entry) != null && rightChild(entry) != null) - { - swapWithSuccessor(entry); - } - - // Then deal with the easy doubly linked list deletion (need to do - // this after the swap as the swap uses next - final SortedQueueEntryImpl prev = entry.getPrev(); - if(prev != null) - { - prev.setNext(entry.getNextValidEntry()); - } - - final SortedQueueEntryImpl next = entry.getNextValidEntry(); - if(next != null) - { - next.setPrev(prev); - } - - // now deal with splicing - final SortedQueueEntryImpl chosenChild; - - if(leftChild(entry) != null) - { - chosenChild = leftChild(entry); - } - else - { - chosenChild = rightChild(entry); - } - - if(chosenChild != null) - { - // we have one child (x), we can move it up to replace x - chosenChild.setParent(entry.getParent()); - if(chosenChild.getParent() == null) - { - _root = chosenChild; - } - else if(entry == entry.getParent().getLeft()) - { - entry.getParent().setLeft(chosenChild); - } - else - { - entry.getParent().setRight(chosenChild); - } - - entry.setLeft(null); - entry.setRight(null); - entry.setParent(null); - - if(entry.getColour() == Colour.BLACK) - { - deleteFixup(chosenChild); - } - - } - else - { - // no children - if(entry.getParent() == null) - { - // no parent either - the tree is empty - _root = null; - } - else - { - if(entry.getColour() == Colour.BLACK) - { - deleteFixup(entry); - } - - if(entry.getParent() != null) - { - if(entry.getParent().getLeft() == entry) - { - entry.getParent().setLeft(null); - } - else if(entry.getParent().getRight() == entry) - { - entry.getParent().setRight(null); - } - entry.setParent(null); - } - } - } - - } - } - - public int getPriorities() - { - return 0; - } - - /** - * Swaps the position of the node in the tree with it's successor - * (that is the node with the next highest key) - * @param entry - */ - private void swapWithSuccessor(final SortedQueueEntryImpl entry) - { - final SortedQueueEntryImpl next = entry.getNextValidEntry(); - final SortedQueueEntryImpl nextParent = next.getParent(); - final SortedQueueEntryImpl nextLeft = next.getLeft(); - final SortedQueueEntryImpl nextRight = next.getRight(); - final Colour nextColour = next.getColour(); - - // Special case - the successor is the right child of the node - if(next == entry.getRight()) - { - next.setParent(entry.getParent()); - if(next.getParent() == null) - { - _root = next; - } - else if(next.getParent().getLeft() == entry) - { - next.getParent().setLeft(next); - } - else - { - next.getParent().setRight(next); - } - - next.setRight(entry); - entry.setParent(next); - next.setLeft(entry.getLeft()); - - if(next.getLeft() != null) - { - next.getLeft().setParent(next); - } - - next.setColour(entry.getColour()); - entry.setColour(nextColour); - entry.setLeft(nextLeft); - - if(nextLeft != null) - { - nextLeft.setParent(entry); - } - entry.setRight(nextRight); - if(nextRight != null) - { - nextRight.setParent(entry); - } - } - else - { - next.setParent(entry.getParent()); - if(next.getParent() == null) - { - _root = next; - } - else if(next.getParent().getLeft() == entry) - { - next.getParent().setLeft(next); - } - else - { - next.getParent().setRight(next); - } - - next.setLeft(entry.getLeft()); - if(next.getLeft() != null) - { - next.getLeft().setParent(next); - } - next.setRight(entry.getRight()); - if(next.getRight() != null) - { - next.getRight().setParent(next); - } - next.setColour(entry.getColour()); - - entry.setParent(nextParent); - if(nextParent.getLeft() == next) - { - nextParent.setLeft(entry); - } - else - { - nextParent.setRight(entry); - } - - entry.setLeft(nextLeft); - if(nextLeft != null) - { - nextLeft.setParent(entry); - } - entry.setRight(nextRight); - if(nextRight != null) - { - nextRight.setParent(entry); - } - entry.setColour(nextColour); - } - } - - private void deleteFixup(SortedQueueEntryImpl entry) - { - int i = 0; - while(entry != null && entry != _root - && isNodeColour(entry, Colour.BLACK)) - { - i++; - - if(i > 1000) - { - return; - } - - if(entry == leftChild(nodeParent(entry))) - { - SortedQueueEntryImpl rightSibling = rightChild(nodeParent(entry)); - if(isNodeColour(rightSibling, Colour.RED)) - { - setColour(rightSibling, Colour.BLACK); - nodeParent(entry).setColour(Colour.RED); - leftRotate(nodeParent(entry)); - rightSibling = rightChild(nodeParent(entry)); - } - - if(isNodeColour(leftChild(rightSibling), Colour.BLACK) - && isNodeColour(rightChild(rightSibling), Colour.BLACK)) - { - setColour(rightSibling, Colour.RED); - entry = nodeParent(entry); - } - else - { - if(isNodeColour(rightChild(rightSibling), Colour.BLACK)) - { - setColour(leftChild(rightSibling), Colour.BLACK); - rightSibling.setColour(Colour.RED); - rightRotate(rightSibling); - rightSibling = rightChild(nodeParent(entry)); - } - setColour(rightSibling, getColour(nodeParent(entry))); - setColour(nodeParent(entry), Colour.BLACK); - setColour(rightChild(rightSibling), Colour.BLACK); - leftRotate(nodeParent(entry)); - entry = _root; - } - } - else - { - SortedQueueEntryImpl leftSibling = leftChild(nodeParent(entry)); - if(isNodeColour(leftSibling, Colour.RED)) - { - setColour(leftSibling, Colour.BLACK); - nodeParent(entry).setColour(Colour.RED); - rightRotate(nodeParent(entry)); - leftSibling = leftChild(nodeParent(entry)); - } - - if(isNodeColour(leftChild(leftSibling), Colour.BLACK) - && isNodeColour(rightChild(leftSibling), Colour.BLACK)) - { - setColour(leftSibling, Colour.RED); - entry = nodeParent(entry); - } - else - { - if(isNodeColour(leftChild(leftSibling), Colour.BLACK)) - { - setColour(rightChild(leftSibling), Colour.BLACK); - leftSibling.setColour(Colour.RED); - leftRotate(leftSibling); - leftSibling = leftChild(nodeParent(entry)); - } - setColour(leftSibling, getColour(nodeParent(entry))); - setColour(nodeParent(entry), Colour.BLACK); - setColour(leftChild(leftSibling), Colour.BLACK); - rightRotate(nodeParent(entry)); - entry = _root; - } - } - } - setColour(entry, Colour.BLACK); - } - - private Colour getColour(final SortedQueueEntryImpl x) - { - return x == null ? null : x.getColour(); - } - - public class QueueEntryIteratorImpl implements QueueEntryIterator<SortedQueueEntryImpl> - { - private SortedQueueEntryImpl _lastNode; - - public QueueEntryIteratorImpl(final SortedQueueEntryImpl startNode) - { - _lastNode = startNode; - } - - public boolean atTail() - { - return next(_lastNode) == null; - } - - public SortedQueueEntryImpl getNode() - { - return _lastNode; - } - - public boolean advance() - { - if(!atTail()) - { - SortedQueueEntryImpl nextNode = next(_lastNode); - while(nextNode.isDispensed() && next(nextNode) != null) - { - nextNode = next(nextNode); - } - _lastNode = nextNode; - return true; - - } - else - { - return false; - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryListFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryListFactory.java deleted file mode 100644 index 87c79178f0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SortedQueueEntryListFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - -public class SortedQueueEntryListFactory implements QueueEntryListFactory -{ - - private final String _propertyName; - - public SortedQueueEntryListFactory(final String propertyName) - { - _propertyName = propertyName; - } - - @Override - public QueueEntryList<SortedQueueEntryImpl> createQueueEntryList(final AMQQueue queue) - { - return new SortedQueueEntryList(queue, _propertyName); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SubFlushRunner.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SubFlushRunner.java deleted file mode 100755 index 47a7d733dd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SubFlushRunner.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.queue; - - -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.transport.TransportException; - -import java.util.concurrent.Executor; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - - -class SubFlushRunner implements Runnable -{ - private static final Logger _logger = Logger.getLogger(SubFlushRunner.class); - - - private final Subscription _sub; - - private static int IDLE = 0; - private static int SCHEDULED = 1; - private static int RUNNING = 2; - - - private final AtomicInteger _scheduled = new AtomicInteger(IDLE); - - - private static final long ITERATIONS = SimpleAMQQueue.MAX_ASYNC_DELIVERIES; - private final AtomicBoolean _stateChange = new AtomicBoolean(); - - public SubFlushRunner(Subscription sub) - { - _sub = sub; - } - - public void run() - { - if(_scheduled.compareAndSet(SCHEDULED, RUNNING)) - { - boolean complete = false; - _stateChange.set(false); - try - { - CurrentActor.set(_sub.getLogActor()); - complete = getQueue().flushSubscription(_sub, ITERATIONS); - } - catch (AMQException e) - { - _logger.error("Exception during asynchronous delivery by " + toString(), e); - } - catch (final TransportException transe) - { - final String errorMessage = "Problem during asynchronous delivery by " + toString(); - if(_logger.isDebugEnabled()) - { - _logger.debug(errorMessage, transe); - } - else - { - _logger.info(errorMessage + ' ' + transe.getMessage()); - } - } - finally - { - CurrentActor.remove(); - _scheduled.compareAndSet(RUNNING, IDLE); - if ((!complete || _stateChange.compareAndSet(true,false))&& !_sub.isSuspended()) - { - if(_scheduled.compareAndSet(IDLE,SCHEDULED)) - { - getQueue().execute(this); - } - } - } - } - } - - private SimpleAMQQueue getQueue() - { - return (SimpleAMQQueue) _sub.getQueue(); - } - - public String toString() - { - return "SubFlushRunner-" + _sub.getLogActor(); - } - - public void execute(Executor executor) - { - _stateChange.set(true); - if(_scheduled.compareAndSet(IDLE,SCHEDULED)) - { - executor.execute(this); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java deleted file mode 100644 index 9d16f4b927..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java +++ /dev/null @@ -1,355 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.registry; - -import java.util.Collection; -import java.util.Timer; -import java.util.TimerTask; - -import org.apache.log4j.Logger; -import org.apache.qpid.common.Closeable; -import org.apache.qpid.common.QpidProperties; -import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.configuration.startup.DefaultRecovererProvider; -import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener; -import org.apache.qpid.server.logging.CompositeStartupMessageLogger; -import org.apache.qpid.server.logging.Log4jMessageLogger; -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.logging.LogRecorder; -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.SystemOutMessageLogger; -import org.apache.qpid.server.logging.actors.AbstractActor; -import org.apache.qpid.server.logging.actors.BrokerActor; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.actors.GenericActor; -import org.apache.qpid.server.logging.messages.BrokerMessages; -import org.apache.qpid.server.logging.messages.VirtualHostMessages; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.stats.StatisticsCounter; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; - - -/** - * An abstract application registry that provides access to configuration information and handles the - * construction and caching of configurable objects. - * <p/> - * Subclasses should handle the construction of the "registered objects" such as the exchange registry. - */ -public class ApplicationRegistry implements IApplicationRegistry -{ - private static final Logger _logger = Logger.getLogger(ApplicationRegistry.class); - - private final VirtualHostRegistry _virtualHostRegistry = new VirtualHostRegistry(); - - private volatile RootMessageLogger _rootMessageLogger; - - private Broker _broker; - - private Timer _reportingTimer; - private StatisticsCounter _messagesDelivered, _dataDelivered, _messagesReceived, _dataReceived; - - private LogRecorder _logRecorder; - - private ConfigurationEntryStore _store; - private TaskExecutor _taskExecutor; - - protected void setRootMessageLogger(RootMessageLogger rootMessageLogger) - { - _rootMessageLogger = rootMessageLogger; - } - - public ApplicationRegistry(ConfigurationEntryStore store) - { - _store = store; - initialiseStatistics(); - } - - public void initialise(BrokerOptions brokerOptions) throws Exception - { - // Create the RootLogger to be used during broker operation - boolean statusUpdatesEnabled = Boolean.parseBoolean(System.getProperty(BrokerProperties.PROPERTY_STATUS_UPDATES, "true")); - _rootMessageLogger = new Log4jMessageLogger(statusUpdatesEnabled); - - _logRecorder = new LogRecorder(); - - //Create the composite (log4j+SystemOut MessageLogger to be used during startup - RootMessageLogger[] messageLoggers = {new SystemOutMessageLogger(), _rootMessageLogger}; - CompositeStartupMessageLogger startupMessageLogger = new CompositeStartupMessageLogger(messageLoggers); - - BrokerActor actor = new BrokerActor(startupMessageLogger); - CurrentActor.set(actor); - CurrentActor.setDefault(actor); - GenericActor.setDefaultMessageLogger(_rootMessageLogger); - try - { - logStartupMessages(CurrentActor.get()); - - _taskExecutor = new TaskExecutor(); - _taskExecutor.start(); - - StoreConfigurationChangeListener storeChangeListener = new StoreConfigurationChangeListener(_store); - RecovererProvider provider = new DefaultRecovererProvider((StatisticsGatherer)this, _virtualHostRegistry, _logRecorder, _rootMessageLogger, _taskExecutor, brokerOptions, storeChangeListener); - ConfiguredObjectRecoverer<? extends ConfiguredObject> brokerRecoverer = provider.getRecoverer(Broker.class.getSimpleName()); - _broker = (Broker) brokerRecoverer.create(provider, _store.getRootEntry()); - - _virtualHostRegistry.setDefaultVirtualHostName((String)_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST)); - - initialiseStatisticsReporting(); - - // starting the broker - _broker.setDesiredState(State.INITIALISING, State.ACTIVE); - - CurrentActor.get().message(BrokerMessages.READY()); - } - finally - { - CurrentActor.remove(); - } - - CurrentActor.setDefault(new BrokerActor(_rootMessageLogger)); - } - - private void initialiseStatisticsReporting() - { - long report = ((Number)_broker.getAttribute(Broker.STATISTICS_REPORTING_PERIOD)).intValue() * 1000; // convert to ms - final boolean reset = (Boolean)_broker.getAttribute(Broker.STATISTICS_REPORTING_RESET_ENABLED); - - /* add a timer task to report statistics if generation is enabled for broker or virtualhosts */ - if (report > 0L) - { - _reportingTimer = new Timer("Statistics-Reporting", true); - StatisticsReportingTask task = new StatisticsReportingTask(reset, _rootMessageLogger); - _reportingTimer.scheduleAtFixedRate(task, report / 2, report); - } - } - - private class StatisticsReportingTask extends TimerTask - { - private final int DELIVERED = 0; - private final int RECEIVED = 1; - - private final boolean _reset; - private final RootMessageLogger _logger; - - public StatisticsReportingTask(boolean reset, RootMessageLogger logger) - { - _reset = reset; - _logger = logger; - } - - public void run() - { - CurrentActor.set(new AbstractActor(_logger) - { - public String getLogMessage() - { - return "[" + Thread.currentThread().getName() + "] "; - } - }); - try - { - CurrentActor.get().message(BrokerMessages.STATS_DATA(DELIVERED, _dataDelivered.getPeak() / 1024.0, _dataDelivered.getTotal())); - CurrentActor.get().message(BrokerMessages.STATS_MSGS(DELIVERED, _messagesDelivered.getPeak(), _messagesDelivered.getTotal())); - CurrentActor.get().message(BrokerMessages.STATS_DATA(RECEIVED, _dataReceived.getPeak() / 1024.0, _dataReceived.getTotal())); - CurrentActor.get().message(BrokerMessages.STATS_MSGS(RECEIVED, _messagesReceived.getPeak(), _messagesReceived.getTotal())); - Collection<VirtualHost> hosts = _virtualHostRegistry.getVirtualHosts(); - - if (hosts.size() > 1) - { - for (VirtualHost vhost : hosts) - { - String name = vhost.getName(); - StatisticsCounter dataDelivered = vhost.getDataDeliveryStatistics(); - StatisticsCounter messagesDelivered = vhost.getMessageDeliveryStatistics(); - StatisticsCounter dataReceived = vhost.getDataReceiptStatistics(); - StatisticsCounter messagesReceived = vhost.getMessageReceiptStatistics(); - - CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, DELIVERED, dataDelivered.getPeak() / 1024.0, dataDelivered.getTotal())); - CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, DELIVERED, messagesDelivered.getPeak(), messagesDelivered.getTotal())); - CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, RECEIVED, dataReceived.getPeak() / 1024.0, dataReceived.getTotal())); - CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, RECEIVED, messagesReceived.getPeak(), messagesReceived.getTotal())); - } - } - - if (_reset) - { - resetStatistics(); - } - } - catch(Exception e) - { - ApplicationRegistry._logger.warn("Unexpected exception occured while reporting the statistics", e); - } - finally - { - CurrentActor.remove(); - } - } - } - - /** - * Close non-null Closeable items and log any errors - * @param close - */ - private void close(Closeable close) - { - try - { - if (close != null) - { - close.close(); - } - } - catch (Throwable e) - { - _logger.error("Error thrown whilst closing " + close.getClass().getSimpleName(), e); - } - } - - public void close() - { - if (_logger.isInfoEnabled()) - { - _logger.info("Shutting down ApplicationRegistry:" + this); - } - - //Set the Actor for Broker Shutdown - CurrentActor.set(new BrokerActor(_rootMessageLogger)); - try - { - //Stop Statistics Reporting - if (_reportingTimer != null) - { - _reportingTimer.cancel(); - } - - if (_broker != null) - { - _broker.setDesiredState(_broker.getActualState(), State.STOPPED); - } - - //Shutdown virtualhosts - close(_virtualHostRegistry); - - if (_taskExecutor != null) - { - _taskExecutor.stop(); - } - - CurrentActor.get().message(BrokerMessages.STOPPED()); - - _logRecorder.closeLogRecorder(); - - } - finally - { - if (_taskExecutor != null) - { - _taskExecutor.stopImmediately(); - } - CurrentActor.remove(); - } - _store = null; - _broker = null; - } - - public void registerMessageDelivered(long messageSize) - { - _messagesDelivered.registerEvent(1L); - _dataDelivered.registerEvent(messageSize); - } - - public void registerMessageReceived(long messageSize, long timestamp) - { - _messagesReceived.registerEvent(1L, timestamp); - _dataReceived.registerEvent(messageSize, timestamp); - } - - public StatisticsCounter getMessageReceiptStatistics() - { - return _messagesReceived; - } - - public StatisticsCounter getDataReceiptStatistics() - { - return _dataReceived; - } - - public StatisticsCounter getMessageDeliveryStatistics() - { - return _messagesDelivered; - } - - public StatisticsCounter getDataDeliveryStatistics() - { - return _dataDelivered; - } - - public void resetStatistics() - { - _messagesDelivered.reset(); - _dataDelivered.reset(); - _messagesReceived.reset(); - _dataReceived.reset(); - - for (VirtualHost vhost : _virtualHostRegistry.getVirtualHosts()) - { - vhost.resetStatistics(); - } - } - - public void initialiseStatistics() - { - _messagesDelivered = new StatisticsCounter("messages-delivered"); - _dataDelivered = new StatisticsCounter("bytes-delivered"); - _messagesReceived = new StatisticsCounter("messages-received"); - _dataReceived = new StatisticsCounter("bytes-received"); - } - - private void logStartupMessages(LogActor logActor) - { - logActor.message(BrokerMessages.STARTUP(QpidProperties.getReleaseVersion(), QpidProperties.getBuildVersion())); - - logActor.message(BrokerMessages.PLATFORM(System.getProperty("java.vendor"), - System.getProperty("java.runtime.version", System.getProperty("java.version")), - System.getProperty("os.name"), - System.getProperty("os.version"), - System.getProperty("os.arch"))); - - logActor.message(BrokerMessages.MAX_MEMORY(Runtime.getRuntime().maxMemory())); - } - - @Override - public Broker getBroker() - { - return _broker; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java deleted file mode 100644 index 7341922bd0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.registry; - -import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.stats.StatisticsGatherer; - -public interface IApplicationRegistry extends StatisticsGatherer -{ - - void initialise(BrokerOptions brokerOptions) throws Exception; - - /** - * Shutdown this Registry - */ - void close(); - - Broker getBroker(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java deleted file mode 100644 index 61e928a38c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security; - -import org.apache.qpid.server.security.access.ObjectProperties; -import org.apache.qpid.server.security.access.ObjectType; -import org.apache.qpid.server.security.access.Operation; - -/** - * The two methods, {@link #access(ObjectType, Object)} and {@link #authorise(Operation, ObjectType, ObjectProperties)}, - * return the {@link Result} of the security decision, which may be to {@link Result#ABSTAIN} if no decision is made. - */ -public interface AccessControl -{ - /** - * Default result for {@link #access(ObjectType, Object)} or {@link #authorise(Operation, ObjectType, ObjectProperties)}. - */ - Result getDefault(); - - /** - * Authorise access granted to an object instance. - */ - Result access(ObjectType objectType, Object instance); - - /** - * Authorise an operation on an object defined by a set of properties. - */ - Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties); - - /** - * Called to open any resources required by the implementation. - */ - void open(); - - /** - * Called to close any resources required by the implementation. - */ - void close(); - - /** - * Called when deleting to allow clearing any resources used by the implementation. - */ - void onDelete(); - - /** - * Called when first creating (but not when recovering after startup) to allow - * creating any resources required by the implementation. - */ - void onCreate(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AuthorizationHolder.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AuthorizationHolder.java deleted file mode 100755 index 8243fc3f75..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AuthorizationHolder.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security; - -import javax.security.auth.Subject; -import java.security.Principal; - -/** - * Represents the authorization of the logged on user. - * - */ -public interface AuthorizationHolder -{ - /** - * Returns the {@link Subject} of the authorized user. This is guaranteed to - * contain at least one {@link org.apache.qpid.server.security.auth.UsernamePrincipal}, representing the the identity - * used when the user logged on to the application, and zero or more {@link org.apache.qpid.server.security.auth.sasl.GroupPrincipal} - * representing the group(s) to which the user belongs. - * - * @return the Subject - */ - Subject getAuthorizedSubject(); - - /** - * Returns the {@link Principal} representing the the identity - * used when the user logged on to the application. - * - * @return a Principal - */ - Principal getAuthorizedPrincipal(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/Result.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/Result.java deleted file mode 100644 index f79721799e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/Result.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security; - -/** - * The result of a security plugin decision, normally {@link #ALLOWED} or {@link #DENIED}. - */ -public enum Result -{ - /** - * The request is allowed. - */ - ALLOWED, - - /** - * The request is denied. - */ - DENIED, - - /** - * Indicates that a plugin does not handle a particular type of request. - */ - ABSTAIN, - - /** - * A plugin instance cannot make a decision on a request it is able to handle, - * and another instance of the plugin should be checked. - */ - DEFER; -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java deleted file mode 100755 index ff45add206..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security; - -import org.apache.log4j.Logger; - -import org.apache.qpid.server.exchange.Exchange; - -import org.apache.qpid.server.model.AccessControlProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfigurationChangeListener; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.plugin.AccessControlFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.security.access.FileAccessControlProviderConstants; -import org.apache.qpid.server.security.access.ObjectProperties; -import org.apache.qpid.server.security.access.ObjectType; -import org.apache.qpid.server.security.access.Operation; -import org.apache.qpid.server.security.access.OperationLoggingDetails; - -import static org.apache.qpid.server.security.access.ObjectType.BROKER; -import static org.apache.qpid.server.security.access.ObjectType.EXCHANGE; -import static org.apache.qpid.server.security.access.ObjectType.GROUP; -import static org.apache.qpid.server.security.access.ObjectType.METHOD; -import static org.apache.qpid.server.security.access.ObjectType.QUEUE; -import static org.apache.qpid.server.security.access.ObjectType.USER; -import static org.apache.qpid.server.security.access.ObjectType.VIRTUALHOST; -import static org.apache.qpid.server.security.access.Operation.ACCESS_LOGS; -import static org.apache.qpid.server.security.access.Operation.BIND; -import static org.apache.qpid.server.security.access.Operation.CONFIGURE; -import static org.apache.qpid.server.security.access.Operation.CONSUME; -import static org.apache.qpid.server.security.access.Operation.CREATE; -import static org.apache.qpid.server.security.access.Operation.DELETE; -import static org.apache.qpid.server.security.access.Operation.PUBLISH; -import static org.apache.qpid.server.security.access.Operation.PURGE; -import static org.apache.qpid.server.security.access.Operation.UNBIND; -import static org.apache.qpid.server.security.access.Operation.UPDATE; - -import javax.security.auth.Subject; -import java.net.SocketAddress; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - -public class SecurityManager implements ConfigurationChangeListener -{ - private static final Logger _logger = Logger.getLogger(SecurityManager.class); - - /** Container for the {@link java.security.Principal} that is using to this thread. */ - private static final ThreadLocal<Subject> _subject = new ThreadLocal<Subject>(); - - public static final ThreadLocal<Boolean> _accessChecksDisabled = new ClearingThreadLocal(false); - - private ConcurrentHashMap<String, AccessControl> _globalPlugins = new ConcurrentHashMap<String, AccessControl>(); - private ConcurrentHashMap<String, AccessControl> _hostPlugins = new ConcurrentHashMap<String, AccessControl>(); - - private boolean _managementMode; - - private Broker _broker; - - /** - * A special ThreadLocal, which calls remove() on itself whenever the value is - * the default, to avoid leaving a default value set after its use has passed. - */ - private static final class ClearingThreadLocal extends ThreadLocal<Boolean> - { - private Boolean _defaultValue; - - public ClearingThreadLocal(Boolean defaultValue) - { - super(); - _defaultValue = defaultValue; - } - - @Override - protected Boolean initialValue() - { - return _defaultValue; - } - - @Override - public void set(Boolean value) - { - if (value == _defaultValue) - { - super.remove(); - } - else - { - super.set(value); - } - } - - @Override - public Boolean get() - { - Boolean value = super.get(); - if (value == _defaultValue) - { - super.remove(); - } - return value; - } - } - - /* - * Used by the Broker. - */ - public SecurityManager(Broker broker, boolean managementMode) - { - _managementMode = managementMode; - _broker = broker; - } - - /* - * Used by the VirtualHost to allow deferring to the broker level security plugins if required. - */ - public SecurityManager(SecurityManager parent, String aclFile, String vhostName) - { - _managementMode = parent._managementMode; - - if(!_managementMode) - { - configureVirtualHostAclPlugin(aclFile, vhostName); - - // our global plugins are the parent's host plugins - _globalPlugins = parent._hostPlugins; - } - } - - private void configureVirtualHostAclPlugin(String aclFile, String vhostName) - { - if(aclFile != null) - { - Map<String, Object> attributes = new HashMap<String, Object>(); - - attributes.put(AccessControlProvider.TYPE, FileAccessControlProviderConstants.ACL_FILE_PROVIDER_TYPE); - attributes.put(FileAccessControlProviderConstants.PATH, aclFile); - - for (AccessControlFactory provider : (new QpidServiceLoader<AccessControlFactory>()).instancesOf(AccessControlFactory.class)) - { - AccessControl accessControl = provider.createInstance(attributes); - accessControl.open(); - if(accessControl != null) - { - String pluginTypeName = getPluginTypeName(accessControl); - _hostPlugins.put(pluginTypeName, accessControl); - - if(_logger.isDebugEnabled()) - { - _logger.debug("Added access control to host plugins with name: " + vhostName); - } - - break; - } - } - } - - if(_logger.isDebugEnabled()) - { - _logger.debug("Configured " + _hostPlugins.size() + " access control plugins"); - } - } - - private String getPluginTypeName(AccessControl accessControl) - { - return accessControl.getClass().getName(); - } - - public static Subject getThreadSubject() - { - return _subject.get(); - } - - public static void setThreadSubject(final Subject subject) - { - _subject.set(subject); - } - - public static Logger getLogger() - { - return _logger; - } - - private abstract class AccessCheck - { - abstract Result allowed(AccessControl plugin); - } - - private boolean checkAllPlugins(AccessCheck checker) - { - if(_accessChecksDisabled.get()) - { - return true; - } - - Map<String, AccessControl> remainingPlugins = _globalPlugins.isEmpty() - ? Collections.<String, AccessControl>emptyMap() - : _hostPlugins.isEmpty() ? _globalPlugins : new HashMap<String, AccessControl>(_globalPlugins); - - if(!_hostPlugins.isEmpty()) - { - for (Entry<String, AccessControl> hostEntry : _hostPlugins.entrySet()) - { - // Create set of global only plugins - AccessControl globalPlugin = remainingPlugins.get(hostEntry.getKey()); - if (globalPlugin != null) - { - remainingPlugins.remove(hostEntry.getKey()); - } - - Result host = checker.allowed(hostEntry.getValue()); - - if (host == Result.DENIED) - { - // Something vetoed the access, we're done - return false; - } - - // host allow overrides global allow, so only check global on abstain or defer - if (host != Result.ALLOWED) - { - if (globalPlugin == null) - { - if (host == Result.DEFER) - { - host = hostEntry.getValue().getDefault(); - } - if (host == Result.DENIED) - { - return false; - } - } - else - { - Result global = checker.allowed(globalPlugin); - if (global == Result.DEFER) - { - global = globalPlugin.getDefault(); - } - if (global == Result.ABSTAIN && host == Result.DEFER) - { - global = hostEntry.getValue().getDefault(); - } - if (global == Result.DENIED) - { - return false; - } - } - } - } - } - - for (AccessControl plugin : remainingPlugins.values()) - { - Result remaining = checker.allowed(plugin); - if (remaining == Result.DEFER) - { - remaining = plugin.getDefault(); - } - if (remaining == Result.DENIED) - { - return false; - } - } - - // getting here means either allowed or abstained from all plugins - return true; - } - - public boolean authoriseBind(final Exchange exch, final AMQQueue queue, final String routingKey) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(BIND, EXCHANGE, new ObjectProperties(exch, queue, routingKey)); - } - }); - } - - public boolean authoriseMethod(final Operation operation, final String componentName, final String methodName) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - ObjectProperties properties = new ObjectProperties(); - properties.setName(methodName); - if (componentName != null) - { - // Only set the property if there is a component name - properties.put(ObjectProperties.Property.COMPONENT, componentName); - } - return plugin.authorise(operation, METHOD, properties); - } - }); - } - - public boolean accessManagement() - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.access(ObjectType.MANAGEMENT, null); - } - }); - } - - public boolean accessVirtualhost(final String vhostname, final SocketAddress remoteAddress) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.access(VIRTUALHOST, remoteAddress); - } - }); - } - - public boolean authoriseConsume(final AMQQueue queue) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(CONSUME, QUEUE, new ObjectProperties(queue)); - } - }); - } - - public boolean authoriseCreateExchange(final Boolean autoDelete, final Boolean durable, final String exchangeName, - final Boolean internal, final Boolean nowait, final Boolean passive, final String exchangeType) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(CREATE, EXCHANGE, new ObjectProperties(autoDelete, durable, exchangeName, - internal, nowait, passive, exchangeType)); - } - }); - } - - public boolean authoriseCreateQueue(final Boolean autoDelete, final Boolean durable, final Boolean exclusive, - final Boolean nowait, final Boolean passive, final String queueName, final String owner) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(CREATE, QUEUE, new ObjectProperties(autoDelete, durable, exclusive, nowait, passive, queueName, owner)); - } - }); - } - - public boolean authoriseDelete(final AMQQueue queue) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(DELETE, QUEUE, new ObjectProperties(queue)); - } - }); - } - - - public boolean authoriseUpdate(final AMQQueue queue) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(UPDATE, QUEUE, new ObjectProperties(queue)); - } - }); - } - - - public boolean authoriseUpdate(final Exchange exchange) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(UPDATE, EXCHANGE, new ObjectProperties(exchange.getName())); - } - }); - } - - public boolean authoriseDelete(final Exchange exchange) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(DELETE, EXCHANGE, new ObjectProperties(exchange.getName())); - } - }); - } - - public boolean authoriseGroupOperation(final Operation operation, final String groupName) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(operation, GROUP, new ObjectProperties(groupName)); - } - }); - } - - public boolean authoriseUserOperation(final Operation operation, final String userName) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(operation, USER, new ObjectProperties(userName)); - } - }); - } - - private ConcurrentHashMap<String, ConcurrentHashMap<String, PublishAccessCheck>> _immediatePublishPropsCache - = new ConcurrentHashMap<String, ConcurrentHashMap<String, PublishAccessCheck>>(); - private ConcurrentHashMap<String, ConcurrentHashMap<String, PublishAccessCheck>> _publishPropsCache - = new ConcurrentHashMap<String, ConcurrentHashMap<String, PublishAccessCheck>>(); - - public boolean authorisePublish(final boolean immediate, String routingKey, String exchangeName) - { - if(routingKey == null) - { - routingKey = ""; - } - if(exchangeName == null) - { - exchangeName = ""; - } - PublishAccessCheck check; - ConcurrentHashMap<String, ConcurrentHashMap<String, PublishAccessCheck>> cache = - immediate ? _immediatePublishPropsCache : _publishPropsCache; - - ConcurrentHashMap<String, PublishAccessCheck> exchangeMap = cache.get(exchangeName); - if(exchangeMap == null) - { - cache.putIfAbsent(exchangeName, new ConcurrentHashMap<String, PublishAccessCheck>()); - exchangeMap = cache.get(exchangeName); - } - - check = exchangeMap.get(routingKey); - if(check == null) - { - check = new PublishAccessCheck(new ObjectProperties(exchangeName, routingKey, immediate)); - exchangeMap.put(routingKey, check); - } - - return checkAllPlugins(check); - } - - public boolean authorisePurge(final AMQQueue queue) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(PURGE, QUEUE, new ObjectProperties(queue)); - } - }); - } - - public boolean authoriseUnbind(final Exchange exch, final String routingKey, final AMQQueue queue) - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(UNBIND, EXCHANGE, new ObjectProperties(exch, queue, routingKey)); - } - }); - } - - public static boolean setAccessChecksDisabled(final boolean status) - { - //remember current value - boolean current = _accessChecksDisabled.get(); - - _accessChecksDisabled.set(status); - - return current; - } - - private class PublishAccessCheck extends AccessCheck - { - private final ObjectProperties _props; - - public PublishAccessCheck(ObjectProperties props) - { - _props = props; - } - - Result allowed(AccessControl plugin) - { - return plugin.authorise(PUBLISH, EXCHANGE, _props); - } - } - - @Override - public void stateChanged(ConfiguredObject object, State oldState, State newState) - { - if(_managementMode) - { - //AccessControl is disabled in ManagementMode - return; - } - - if(object instanceof AccessControlProvider) - { - if(newState == State.ACTIVE) - { - synchronized (_hostPlugins) - { - AccessControl accessControl = ((AccessControlProvider)object).getAccessControl(); - String pluginTypeName = getPluginTypeName(accessControl); - - _hostPlugins.put(pluginTypeName, accessControl); - } - } - else if(newState == State.DELETED) - { - synchronized (_hostPlugins) - { - AccessControl control = ((AccessControlProvider)object).getAccessControl(); - String pluginTypeName = getPluginTypeName(control); - - // Remove the type->control mapping for this type key only if the - // given control is actually referred to. - if(_hostPlugins.containsValue(control)) - { - // If we are removing this control, check if another of the same - // type already exists on the broker and use it in instead. - AccessControl other = null; - Collection<AccessControlProvider> providers = _broker.getAccessControlProviders(); - for(AccessControlProvider p : providers) - { - if(p == object || p.getActualState() != State.ACTIVE) - { - //we don't count ourself as another - continue; - } - - AccessControl ac = p.getAccessControl(); - if(pluginTypeName.equals(getPluginTypeName(ac))) - { - other = ac; - break; - } - } - - if(other != null) - { - //Another control of this type was found, use it instead - _hostPlugins.replace(pluginTypeName, control, other); - } - else - { - //No other was found, remove the type entirely - _hostPlugins.remove(pluginTypeName); - } - } - } - } - } - } - - @Override - public void childAdded(ConfiguredObject object, ConfiguredObject child) - { - // no op - } - - @Override - public void childRemoved(ConfiguredObject object, ConfiguredObject child) - { - // no op - } - - @Override - public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue) - { - // no op - } - - public boolean authoriseConfiguringBroker(String configuredObjectName, Class<? extends ConfiguredObject> configuredObjectType, Operation configuredObjectOperation) - { - String description = String.format("%s %s '%s'", - configuredObjectOperation == null? null : configuredObjectOperation.name().toLowerCase(), - configuredObjectType == null ? null : configuredObjectType.getSimpleName().toLowerCase(), - configuredObjectName); - final OperationLoggingDetails properties = new OperationLoggingDetails(description); - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(CONFIGURE, BROKER, properties); - } - }); - } - - public boolean authoriseLogsAccess() - { - return checkAllPlugins(new AccessCheck() - { - Result allowed(AccessControl plugin) - { - return plugin.authorise(ACCESS_LOGS, BROKER, ObjectProperties.EMPTY); - } - }); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SubjectCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SubjectCreator.java deleted file mode 100644 index 244ab0dd94..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SubjectCreator.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security; - -import java.security.Principal; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import javax.security.auth.Subject; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.qpid.server.model.GroupProvider; -import org.apache.qpid.server.security.auth.AuthenticatedPrincipal; -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; -import org.apache.qpid.server.security.auth.SubjectAuthenticationResult; -import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; - -/** - * Creates a {@link Subject} formed by the {@link Principal}'s returned from: - * <ol> - * <li>Authenticating using an {@link AuthenticationManager}</li> - * <li>A {@link GroupPrincipalAccessor}</li> - * </ol> - * - * <p> - * SubjectCreator is a facade to the {@link AuthenticationManager}, and is intended to be - * the single place that {@link Subject}'s are created in the broker. - * </p> - */ -public class SubjectCreator -{ - private AuthenticationManager _authenticationManager; - private Collection<GroupProvider> _groupProviders; - - public SubjectCreator(AuthenticationManager authenticationManager, Collection<GroupProvider> groupProviders) - { - _authenticationManager = authenticationManager; - _groupProviders = groupProviders; - } - - /** - * Gets the known SASL mechanisms - * - * @return SASL mechanism names, space separated. - */ - public String getMechanisms() - { - return _authenticationManager.getMechanisms(); - } - - /** - * @see AuthenticationManager#createSaslServer(String, String, Principal) - */ - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - return _authenticationManager.createSaslServer(mechanism, localFQDN, externalPrincipal); - } - - /** - * Authenticates a user using SASL negotiation. - * - * @param server SASL server - * @param response SASL response to process - */ - public SubjectAuthenticationResult authenticate(SaslServer server, byte[] response) - { - AuthenticationResult authenticationResult = _authenticationManager.authenticate(server, response); - if(server.isComplete()) - { - String username = server.getAuthorizationID(); - - return createResultWithGroups(username, authenticationResult); - } - else - { - return new SubjectAuthenticationResult(authenticationResult); - } - } - - /** - * Authenticates a user using their username and password. - */ - public SubjectAuthenticationResult authenticate(String username, String password) - { - final AuthenticationResult authenticationResult = _authenticationManager.authenticate(username, password); - - return createResultWithGroups(username, authenticationResult); - } - - private SubjectAuthenticationResult createResultWithGroups(String username, final AuthenticationResult authenticationResult) - { - if(authenticationResult.getStatus() == AuthenticationStatus.SUCCESS) - { - final Subject authenticationSubject = new Subject(); - - authenticationSubject.getPrincipals().addAll(authenticationResult.getPrincipals()); - authenticationSubject.getPrincipals().addAll(getGroupPrincipals(username)); - - authenticationSubject.setReadOnly(); - - return new SubjectAuthenticationResult(authenticationResult, authenticationSubject); - } - else - { - return new SubjectAuthenticationResult(authenticationResult); - } - } - - public Subject createSubjectWithGroups(String username) - { - Subject authenticationSubject = new Subject(); - - authenticationSubject.getPrincipals().add(new AuthenticatedPrincipal(username)); - authenticationSubject.getPrincipals().addAll(getGroupPrincipals(username)); - authenticationSubject.setReadOnly(); - - return authenticationSubject; - } - - public Set<Principal> getGroupPrincipals(String username) - { - Set<Principal> principals = new HashSet<Principal>(); - for (GroupProvider groupProvider : _groupProviders) - { - Set<Principal> groups = groupProvider.getGroupPrincipalsForUser(username); - if (groups != null) - { - principals.addAll(groups); - } - } - - return Collections.unmodifiableSet(principals); - } - - public boolean isAnonymousAuthenticationAllowed() - { - return _authenticationManager instanceof AnonymousAuthenticationManager; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/FileAccessControlProviderConstants.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/FileAccessControlProviderConstants.java deleted file mode 100644 index 3a98a947df..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/FileAccessControlProviderConstants.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.access; - -public class FileAccessControlProviderConstants -{ - public static final String ACL_FILE_PROVIDER_TYPE = "AclFile"; - public static final String PATH = "path"; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java deleted file mode 100644 index a379f85bbb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.access; - -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.queue.AMQQueue; - -/** - * An set of properties for an access control v2 rule {@link ObjectType}. - * - * The {@link #matches(ObjectProperties)} method is intended to be used when determining precedence of rules, and - * {@link #equals(Object)} and {@link #hashCode()} are intended for use in maps. This is due to the wildcard matching - * described above. - */ -public class ObjectProperties -{ - public static final String STAR= "*"; - - public static final ObjectProperties EMPTY = new ObjectProperties(); - - public enum Property - { - ROUTING_KEY, - NAME, - QUEUE_NAME, - OWNER, - TYPE, - ALTERNATE, - IMMEDIATE, - INTERNAL, - NO_WAIT, - NO_LOCAL, - NO_ACK, - PASSIVE, - DURABLE, - EXCLUSIVE, - TEMPORARY, - AUTO_DELETE, - COMPONENT, - PACKAGE, - CLASS, - FROM_NETWORK, - FROM_HOSTNAME; - - private static final Map<String, Property> _canonicalNameToPropertyMap = new HashMap<String, ObjectProperties.Property>(); - - static - { - for (Property property : values()) - { - _canonicalNameToPropertyMap.put(getCanonicalName(property.name()), property); - } - } - - /** - * Properties are parsed using their canonical name (see {@link #getCanonicalName(String)}) - * so that, for the sake of user-friendliness, the ACL file parses is insensitive to - * case and underscores. - */ - public static Property parse(String text) - { - String propertyName = getCanonicalName(text); - Property property = _canonicalNameToPropertyMap.get(propertyName); - - if(property == null) - { - throw new IllegalArgumentException("Not a valid property: " + text - + " because " + propertyName - + " is not in " + _canonicalNameToPropertyMap.keySet()); - } - else - { - return property; - } - } - - private static String getCanonicalName(String name) - { - return StringUtils.remove(name, '_').toLowerCase(); - } - } - - private final EnumMap<Property, String> _properties = new EnumMap<Property, String>(Property.class); - - public static List<String> getAllPropertyNames() - { - List<String> properties = new ArrayList<String>(); - for (Property property : Property.values()) - { - properties.add(StringUtils.remove(property.name(), '_').toLowerCase()); - } - return properties; - } - - public ObjectProperties() - { - } - - public ObjectProperties(Property property, String value) - { - _properties.put(property, value); - } - - public ObjectProperties(ObjectProperties copy) - { - _properties.putAll(copy._properties); - } - - public ObjectProperties(String name) - { - setName(name); - } - - public ObjectProperties(AMQQueue queue) - { - setName(queue.getName()); - - put(Property.AUTO_DELETE, queue.isAutoDelete()); - put(Property.TEMPORARY, queue.isAutoDelete()); - put(Property.DURABLE, queue.isDurable()); - put(Property.EXCLUSIVE, queue.isExclusive()); - if (queue.getAlternateExchange() != null) - { - put(Property.ALTERNATE, queue.getAlternateExchange().getName()); - } - if (queue.getOwner() != null) - { - put(Property.OWNER, queue.getOwner()); - } - else if (queue.getAuthorizationHolder() != null) - { - put(Property.OWNER, queue.getAuthorizationHolder().getAuthorizedPrincipal().getName()); - } - } - - public ObjectProperties(Exchange exch, AMQQueue queue, String routingKey) - { - this(queue); - - setName(exch.getName()); - - put(Property.QUEUE_NAME, queue.getName()); - put(Property.ROUTING_KEY, routingKey); - } - - public ObjectProperties(String exchangeName, String routingKey, Boolean immediate) - { - this(exchangeName, routingKey); - - put(Property.IMMEDIATE, immediate); - } - - public ObjectProperties(String exchangeName, String routingKey) - { - super(); - - setName(exchangeName); - - put(Property.ROUTING_KEY, routingKey); - } - - public ObjectProperties(Boolean autoDelete, Boolean durable, String exchangeName, - Boolean internal, Boolean nowait, Boolean passive, String exchangeType) - { - super(); - - setName(exchangeName); - - put(Property.AUTO_DELETE, autoDelete); - put(Property.TEMPORARY, autoDelete); - put(Property.DURABLE, durable); - put(Property.INTERNAL, internal); - put(Property.NO_WAIT, nowait); - put(Property.PASSIVE, passive); - put(Property.TYPE, exchangeType); - } - - public ObjectProperties(Boolean autoDelete, Boolean durable, Boolean exclusive, Boolean nowait, Boolean passive, - String queueName, String owner) - { - super(); - - setName(queueName); - - put(Property.AUTO_DELETE, autoDelete); - put(Property.TEMPORARY, autoDelete); - put(Property.DURABLE, durable); - put(Property.EXCLUSIVE, exclusive); - put(Property.NO_WAIT, nowait); - put(Property.PASSIVE, passive); - put(Property.OWNER, owner); - } - - public ObjectProperties(Boolean exclusive, Boolean noAck, Boolean noLocal, Boolean nowait, AMQQueue queue) - { - this(queue); - - put(Property.NO_LOCAL, noLocal); - put(Property.NO_ACK, noAck); - put(Property.EXCLUSIVE, exclusive); - put(Property.NO_WAIT, nowait); - } - - public Boolean isSet(Property key) - { - return _properties.containsKey(key) && Boolean.valueOf(_properties.get(key)); - } - - public String get(Property key) - { - return _properties.get(key); - } - - public String getName() - { - return _properties.get(Property.NAME); - } - - public void setName(String name) - { - _properties.put(Property.NAME, name); - } - - public String put(Property key, String value) - { - return _properties.put(key, value == null ? "" : value.trim()); - } - - public void put(Property key, Boolean value) - { - if (value != null) - { - _properties.put(key, Boolean.toString(value)); - } - } - - public boolean matches(ObjectProperties properties) - { - if (properties._properties.keySet().isEmpty()) - { - return true; - } - - if (!_properties.keySet().containsAll(properties._properties.keySet())) - { - return false; - } - - for (Map.Entry<Property,String> entry : properties._properties.entrySet()) - { - Property key = entry.getKey(); - String ruleValue = entry.getValue(); - - String thisValue = _properties.get(key); - - if (!valueMatches(thisValue, ruleValue)) - { - return false; - } - } - - return true; - } - - private boolean valueMatches(String thisValue, String ruleValue) - { - return (StringUtils.isEmpty(ruleValue) - || StringUtils.equals(thisValue, ruleValue)) - || ruleValue.equals(STAR) - || (ruleValue.endsWith(STAR) - && thisValue != null - && thisValue.length() >= ruleValue.length() - 1 - && thisValue.startsWith(ruleValue.substring(0, ruleValue.length() - 1))); - } - - @Override - public boolean equals(Object obj) - { - if (obj == null) - { - return false; - } - if (obj == this) - { - return true; - } - if (obj.getClass() != getClass()) - { - return false; - } - ObjectProperties rhs = (ObjectProperties) obj; - return new EqualsBuilder() - .append(_properties, rhs._properties).isEquals(); - } - - @Override - public int hashCode() - { - return _properties != null ? _properties.hashCode() : 0; - } - - @Override - public String toString() - { - return _properties.toString(); - } - - public boolean isEmpty() - { - return _properties.isEmpty(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectType.java deleted file mode 100644 index 9016205d1c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectType.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.access; - -import static org.apache.qpid.server.security.access.Operation.ACCESS; -import static org.apache.qpid.server.security.access.Operation.ACCESS_LOGS; -import static org.apache.qpid.server.security.access.Operation.BIND; -import static org.apache.qpid.server.security.access.Operation.CONFIGURE; -import static org.apache.qpid.server.security.access.Operation.CONSUME; -import static org.apache.qpid.server.security.access.Operation.CREATE; -import static org.apache.qpid.server.security.access.Operation.DELETE; -import static org.apache.qpid.server.security.access.Operation.PUBLISH; -import static org.apache.qpid.server.security.access.Operation.PURGE; -import static org.apache.qpid.server.security.access.Operation.UNBIND; -import static org.apache.qpid.server.security.access.Operation.UPDATE; - -import java.util.EnumSet; -import java.util.Set; - -/** - * An enumeration of all possible object types that can form part of an access control v2 rule. - * - * Each object type is valid only for a certain set of {@link Operation}s, which are passed as a list to - * the constructor, and can be checked using the {@link #isAllowed(Operation)} method. - */ -public enum ObjectType -{ - ALL(Operation.ALL), - VIRTUALHOST(Operation.ALL, ACCESS), - MANAGEMENT(Operation.ALL, ACCESS), - QUEUE(Operation.ALL, CREATE, DELETE, PURGE, CONSUME, UPDATE), - EXCHANGE(Operation.ALL, ACCESS, CREATE, DELETE, BIND, UNBIND, PUBLISH, UPDATE), - LINK, // Not allowed in the Java broker - ROUTE, // Not allowed in the Java broker - METHOD(Operation.ALL, ACCESS, UPDATE), - USER(Operation.ALL, CREATE, DELETE, UPDATE), - GROUP(Operation.ALL, CREATE, DELETE, UPDATE), - BROKER(Operation.ALL, CONFIGURE, ACCESS_LOGS); - - private EnumSet<Operation> _actions; - - private ObjectType() - { - _actions = EnumSet.noneOf(Operation.class); - } - - private ObjectType(Operation operation) - { - if (operation == Operation.ALL) - { - _actions = EnumSet.allOf(Operation.class); - } - else - { - _actions = EnumSet.of(operation); - } - } - - private ObjectType(Operation first, Operation...rest) - { - _actions = EnumSet.of(first, rest); - } - - public Set<Operation> getActions() - { - return _actions; - } - - public boolean isAllowed(Operation operation) - { - return _actions.contains(operation); - } - - public static ObjectType parse(String text) - { - for (ObjectType object : values()) - { - if (object.name().equalsIgnoreCase(text)) - { - return object; - } - } - throw new IllegalArgumentException("Not a valid object type: " + text); - } - - public String toString() - { - String name = name(); - return name.charAt(0) + name.substring(1).toLowerCase(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/Operation.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/Operation.java deleted file mode 100644 index db5b8fba11..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/Operation.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.access; - -/** - * An enumeration of all possible actions that can form part of an access control v2 rule. - */ -public enum Operation -{ - ALL, - CONSUME, - PUBLISH, - CREATE, - ACCESS, - BIND, - UNBIND, - DELETE, - PURGE, - UPDATE, - CONFIGURE, - ACCESS_LOGS; - - public static Operation parse(String text) - { - for (Operation operation : values()) - { - if (operation.name().equalsIgnoreCase(text)) - { - return operation; - } - } - throw new IllegalArgumentException("Not a valid operation: " + text); - } - - public String toString() - { - String name = name(); - return name.charAt(0) + name.substring(1).toLowerCase(); - } -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/OperationLoggingDetails.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/OperationLoggingDetails.java deleted file mode 100644 index a683199abc..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/OperationLoggingDetails.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.access; - - -public class OperationLoggingDetails extends ObjectProperties -{ - private String _description; - - public OperationLoggingDetails(String description) - { - super(); - _description = description; - } - - @Override - public String toString() - { - StringBuilder sb = new StringBuilder("("); - if (!super.isEmpty()) - { - sb.append("properties=").append(super.toString()); - } - if (_description != null) - { - if (sb.length() > 1) - { - sb.append(", "); - } - sb.append(_description); - } - sb.append(")"); - return sb.toString(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/Permission.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/Permission.java deleted file mode 100644 index 49b3a331f9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/Permission.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.access; - -import org.apache.commons.lang.StringUtils; - -/** - * An enumeration of all possible permissions that can be applied to an access control v2 rule. - */ -public enum Permission -{ - ALLOW, - ALLOW_LOG, - DENY, - DENY_LOG; - - public static Permission parse(String text) - { - - for (Permission permission : values()) - { - if (permission.name().equalsIgnoreCase(StringUtils.replaceChars(text, '-', '_'))) - { - return permission; - } - } - throw new IllegalArgumentException("Not a valid permission: " + text); - } -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipal.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipal.java deleted file mode 100644 index fb31132514..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipal.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth; - -import java.io.Serializable; -import java.security.Principal; -import java.util.Set; - -import javax.security.auth.Subject; - -import org.apache.qpid.server.security.auth.UsernamePrincipal; - -/** - * A simple Principal wrapper. Exists to allow us to identify the "primary" principal - * by calling {@link Subject#getPrincipals(Class)}, passing in {@link AuthenticatedPrincipal}.class, - * e.g. when logging. - */ -public final class AuthenticatedPrincipal implements Principal, Serializable -{ - private final Principal _wrappedPrincipal; - - /** convenience constructor for the common case where we're wrapping a {@link UsernamePrincipal} */ - public AuthenticatedPrincipal(String userPrincipalName) - { - this(new UsernamePrincipal(userPrincipalName)); - } - - public AuthenticatedPrincipal(Principal wrappedPrincipal) - { - if(wrappedPrincipal == null) - { - throw new IllegalArgumentException("Wrapped principal is null"); - } - - _wrappedPrincipal = wrappedPrincipal; - } - - @Override - public String getName() - { - return _wrappedPrincipal.getName(); - } - - @Override - public int hashCode() - { - return _wrappedPrincipal.hashCode(); - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - - if (!(obj instanceof AuthenticatedPrincipal)) - { - return false; - } - - AuthenticatedPrincipal other = (AuthenticatedPrincipal) obj; - - return _wrappedPrincipal.equals(other._wrappedPrincipal); - } - - public static AuthenticatedPrincipal getOptionalAuthenticatedPrincipalFromSubject(final Subject authSubject) - { - return getAuthenticatedPrincipalFromSubject(authSubject, true); - } - - public static AuthenticatedPrincipal getAuthenticatedPrincipalFromSubject(final Subject authSubject) - { - return getAuthenticatedPrincipalFromSubject(authSubject, false); - } - - private static AuthenticatedPrincipal getAuthenticatedPrincipalFromSubject(final Subject authSubject, boolean isPrincipalOptional) - { - if (authSubject == null) - { - throw new IllegalArgumentException("No authenticated subject."); - } - - final Set<AuthenticatedPrincipal> principals = authSubject.getPrincipals(AuthenticatedPrincipal.class); - int numberOfAuthenticatedPrincipals = principals.size(); - - if(numberOfAuthenticatedPrincipals == 0 && isPrincipalOptional) - { - return null; - } - else - { - if (numberOfAuthenticatedPrincipals != 1) - { - throw new IllegalArgumentException( - "Can't find single AuthenticatedPrincipal in authenticated subject. There were " - + numberOfAuthenticatedPrincipals - + " authenticated principals out of a total number of principals of: " + authSubject.getPrincipals()); - } - return principals.iterator().next(); - } - } - - @Override - public String toString() - { - return getName(); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticationResult.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticationResult.java deleted file mode 100644 index 09bf6cf3b1..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticationResult.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth; - -import java.security.Principal; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; - -/** - * Encapsulates the result of an attempt to authenticate using an {@link AuthenticationManager}. - * <p> - * The authentication status describes the overall outcome. - * <p> - * <ol> - * <li>If authentication status is SUCCESS, at least one {@link Principal} will be populated. - * </li> - * <li>If authentication status is CONTINUE, the authentication has failed because the user - * supplied incorrect credentials (etc). If the authentication requires it, the next challenge - * is made available. - * </li> - * <li>If authentication status is ERROR , the authentication decision could not be made due - * to a failure (such as an external system), the {@link AuthenticationResult#getCause()} - * will provide the underlying exception. - * </li> - * </ol> - * - * The main principal provided to the constructor is wrapped in an {@link AuthenticatedPrincipal} - * to make it easier for the rest of the application to identify it among the set of other principals. - */ -public class AuthenticationResult -{ - public enum AuthenticationStatus - { - /** Authentication successful */ - SUCCESS, - /** Authentication not successful due to credentials problem etc */ - CONTINUE, - /** Problem prevented the authentication from being made e.g. failure of an external system */ - ERROR - } - - private final AuthenticationStatus _status; - private final byte[] _challenge; - private final Exception _cause; - private final Set<Principal> _principals = new HashSet<Principal>(); - private final Principal _mainPrincipal; - - public AuthenticationResult(final AuthenticationStatus status) - { - this(null, status, null); - } - - public AuthenticationResult(Principal mainPrincipal) - { - this(mainPrincipal, Collections.<Principal>emptySet()); - } - - public AuthenticationResult(Principal mainPrincipal, Set<Principal> otherPrincipals) - { - AuthenticatedPrincipal specialQpidAuthenticatedPrincipal = new AuthenticatedPrincipal(mainPrincipal); - _principals.addAll(otherPrincipals); - _principals.remove(mainPrincipal); - _principals.add(specialQpidAuthenticatedPrincipal); - _mainPrincipal = mainPrincipal; - - _status = AuthenticationStatus.SUCCESS; - _challenge = null; - _cause = null; - } - - public AuthenticationResult(final byte[] challenge, final AuthenticationStatus status) - { - _challenge = challenge; - _status = status; - _cause = null; - _mainPrincipal = null; - } - - public AuthenticationResult(final AuthenticationStatus error, final Exception cause) - { - _status = error; - _challenge = null; - _cause = cause; - _mainPrincipal = null; - } - - public AuthenticationResult(final byte[] challenge, final AuthenticationStatus status, final Exception cause) - { - if(status == AuthenticationStatus.SUCCESS) - { - throw new IllegalArgumentException("Successful authentication requires at least one principal"); - } - - _status = status; - _challenge = challenge; - _cause = cause; - _mainPrincipal = null; - } - - public Exception getCause() - { - return _cause; - } - - public AuthenticationStatus getStatus() - { - return _status; - } - - public byte[] getChallenge() - { - return _challenge; - } - - public Set<Principal> getPrincipals() - { - return _principals; - } - - public Principal getMainPrincipal() - { - return _mainPrincipal; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/SubjectAuthenticationResult.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/SubjectAuthenticationResult.java deleted file mode 100644 index 3be96b87eb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/SubjectAuthenticationResult.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth; - -import java.security.Principal; - -import javax.security.auth.Subject; - -import org.apache.qpid.server.security.SubjectCreator; - -/** - * Encapsulates the result of an attempt to authenticate using a {@link SubjectCreator}. - * - * <p> - * iff authentication was successful, {@link #getSubject()} will return a non-null value and - * {@link #getStatus()} will return {@link AuthenticationResult.AuthenticationStatus#SUCCESS}. - * - * In this case, the {@link Subject} will contain the user {@link Principal} and zero or more other principals - * representing groups. - * </p> - * @see SubjectCreator - */ -public class SubjectAuthenticationResult -{ - private final AuthenticationResult _authenticationResult; - private final Subject _subject; - - public SubjectAuthenticationResult(AuthenticationResult authenticationResult, Subject subject) - { - _authenticationResult = authenticationResult; - _subject = subject; - } - - public SubjectAuthenticationResult(AuthenticationResult unsuccessfulAuthenticationResult) - { - this(unsuccessfulAuthenticationResult, null); - } - - public Exception getCause() - { - return _authenticationResult.getCause(); - } - - public AuthenticationResult.AuthenticationStatus getStatus() - { - return _authenticationResult.getStatus(); - } - - public byte[] getChallenge() - { - return _authenticationResult.getChallenge(); - } - - public Subject getSubject() - { - return _subject; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/UsernamePrincipal.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/UsernamePrincipal.java deleted file mode 100644 index 5b3c1d59cf..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/UsernamePrincipal.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth; - -import java.io.Serializable; -import java.security.Principal; - -/** A principal that is just a wrapper for a simple username. */ -public class UsernamePrincipal implements Principal, Serializable -{ - private final String _name; - - public UsernamePrincipal(String name) - { - if (name == null) - { - throw new IllegalArgumentException("name cannot be null"); - } - _name = name; - } - - public String getName() - { - return _name; - } - - public String toString() - { - return _name; - } - - @Override - public int hashCode() - { - final int prime = 31; - return prime * _name.hashCode(); - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - else - { - if (obj instanceof UsernamePrincipal) - { - UsernamePrincipal other = (UsernamePrincipal) obj; - return _name.equals(other._name); - } - else - { - return false; - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java deleted file mode 100644 index cb5bc54cd2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java +++ /dev/null @@ -1,465 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.database; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.security.auth.UsernamePrincipal; - -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.login.AccountNotFoundException; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintStream; -import java.security.Principal; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.locks.ReentrantLock; -import java.util.regex.Pattern; - -public abstract class AbstractPasswordFilePrincipalDatabase<U extends PasswordPrincipal> implements PrincipalDatabase -{ - protected static final String DEFAULT_ENCODING = "utf-8"; - - private final Pattern _regexp = Pattern.compile(":"); - private final Map<String, U> _userMap = new HashMap<String, U>(); - private final ReentrantLock _userUpdate = new ReentrantLock(); - private final Random _random = new Random(); - private File _passwordFile; - - public final void open(File passwordFile) throws IOException - { - getLogger().info("PasswordFile using file " + passwordFile.getAbsolutePath()); - _passwordFile = passwordFile; - if (!passwordFile.exists()) - { - throw new FileNotFoundException("Cannot find password file " + passwordFile); - } - if (!passwordFile.canRead()) - { - throw new FileNotFoundException("Cannot read password file " + passwordFile + ". Check permissions."); - } - - loadPasswordFile(); - } - - /** - * SASL Callback Mechanism - sets the Password in the PasswordCallback based on the value in the PasswordFile - * If you want to change the password for a user, use updatePassword instead. - * - * @param principal The Principal to set the password for - * @param callback The PasswordCallback to call setPassword on - * - * @throws javax.security.auth.login.AccountNotFoundException If the Principal cannot be found in this Database - */ - public final void setPassword(Principal principal, PasswordCallback callback) throws AccountNotFoundException - { - if (_passwordFile == null) - { - throw new AccountNotFoundException("Unable to locate principal since no password file was specified during initialisation"); - } - if (principal == null) - { - throw new IllegalArgumentException("principal must not be null"); - } - char[] pwd = lookupPassword(principal.getName()); - - if (pwd != null) - { - callback.setPassword(pwd); - } - else - { - throw new AccountNotFoundException("No account found for principal " + principal); - } - } - - - /** - * Looks up the password for a specified user in the password file. Note this code is <b>not</b> secure since it - * creates strings of passwords. It should be modified to create only char arrays which get nulled out. - * - * @param name The principal name to lookup - * - * @return a char[] for use in SASL. - */ - protected final char[] lookupPassword(String name) - { - U user = _userMap.get(name); - if (user == null) - { - return null; - } - else - { - return user.getPassword(); - } - } - - protected boolean compareCharArray(char[] a, char[] b) - { - boolean equal = false; - if (a.length == b.length) - { - equal = true; - int index = 0; - while (equal && index < a.length) - { - equal = a[index] == b[index]; - index++; - } - } - return equal; - } - - /** - * Changes the password for the specified user - * - * @param principal to change the password for - * @param password plaintext password to set the password too - */ - public boolean updatePassword(Principal principal, char[] password) throws AccountNotFoundException - { - U user = _userMap.get(principal.getName()); - - if (user == null) - { - throw new AccountNotFoundException(principal.getName()); - } - - char[] orig = user.getPassword(); - _userUpdate.lock(); - try - { - user.setPassword(password); - - savePasswordFile(); - - return true; - } - catch (IOException e) - { - getLogger().error("Unable to save password file due to '" + e.getMessage() - + "', password change for user '" + principal + "' discarded"); - //revert the password change - user.restorePassword(orig); - - return false; - } - finally - { - _userUpdate.unlock(); - } - } - - - private void loadPasswordFile() throws IOException - { - try - { - _userUpdate.lock(); - final Map<String, U> newUserMap = new HashMap<String, U>(); - - BufferedReader reader = null; - try - { - reader = new BufferedReader(new FileReader(_passwordFile)); - String line; - - while ((line = reader.readLine()) != null) - { - String[] result = _regexp.split(line); - if (result == null || result.length < 2 || result[0].startsWith("#")) - { - continue; - } - - U user = createUserFromFileData(result); - getLogger().info("Created user:" + user); - newUserMap.put(user.getName(), user); - } - } - finally - { - if (reader != null) - { - reader.close(); - } - } - - _userMap.clear(); - _userMap.putAll(newUserMap); - } - finally - { - _userUpdate.unlock(); - } - } - - protected abstract U createUserFromFileData(String[] result); - - - protected abstract Logger getLogger(); - - protected File createTempFileOnSameFilesystem() - { - File liveFile = _passwordFile; - File tmp; - - do - { - tmp = new File(liveFile.getPath() + _random.nextInt() + ".tmp"); - } - while(tmp.exists()); - - tmp.deleteOnExit(); - return tmp; - } - - protected void swapTempFileToLive(final File temp) throws IOException - { - File live = _passwordFile; - // Remove any existing ".old" file - final File old = new File(live.getAbsoluteFile() + ".old"); - if (old.exists()) - { - old.delete(); - } - - // Create an new ".old" file - if(!live.renameTo(old)) - { - //unable to rename the existing file to the backup name - getLogger().error("Could not backup the existing password file"); - throw new IOException("Could not backup the existing password file"); - } - - // Move temp file to be the new "live" file - if(!temp.renameTo(live)) - { - //failed to rename the new file to the required filename - if(!old.renameTo(live)) - { - //unable to return the backup to required filename - getLogger().error( - "Could not rename the new password file into place, and unable to restore original file"); - throw new IOException("Could not rename the new password file into place, and unable to restore original file"); - } - - getLogger().error("Could not rename the new password file into place"); - throw new IOException("Could not rename the new password file into place"); - } - } - - protected void savePasswordFile() throws IOException - { - try - { - _userUpdate.lock(); - - BufferedReader reader = null; - PrintStream writer = null; - - File tmp = createTempFileOnSameFilesystem(); - - try - { - writer = new PrintStream(tmp); - reader = new BufferedReader(new FileReader(_passwordFile)); - String line; - - while ((line = reader.readLine()) != null) - { - String[] result = _regexp.split(line); - if (result == null || result.length < 2 || result[0].startsWith("#")) - { - writer.write(line.getBytes(DEFAULT_ENCODING)); - writer.println(); - continue; - } - - U user = _userMap.get(result[0]); - - if (user == null) - { - writer.write(line.getBytes(DEFAULT_ENCODING)); - writer.println(); - } - else if (!user.isDeleted()) - { - if (!user.isModified()) - { - writer.write(line.getBytes(DEFAULT_ENCODING)); - writer.println(); - } - else - { - byte[] encodedPassword = user.getEncodedPassword(); - - writer.write((user.getName() + ":").getBytes(DEFAULT_ENCODING)); - writer.write(encodedPassword); - writer.println(); - - user.saved(); - } - } - } - - for (U user : _userMap.values()) - { - if (user.isModified()) - { - byte[] encodedPassword; - encodedPassword = user.getEncodedPassword(); - writer.write((user.getName() + ":").getBytes(DEFAULT_ENCODING)); - writer.write(encodedPassword); - writer.println(); - user.saved(); - } - } - } - catch(IOException e) - { - getLogger().error("Unable to create the new password file: " + e); - throw new IOException("Unable to create the new password file",e); - } - finally - { - - try - { - if (reader != null) - { - reader.close(); - } - } - finally - { - if (writer != null) - { - writer.close(); - } - } - - } - - swapTempFileToLive(tmp); - } - finally - { - _userUpdate.unlock(); - } - } - - protected abstract U createUserFromPassword(Principal principal, char[] passwd); - - - public void reload() throws IOException - { - loadPasswordFile(); - } - - public List<Principal> getUsers() - { - return new LinkedList<Principal>(_userMap.values()); - } - - public Principal getUser(String username) - { - if (_userMap.containsKey(username)) - { - return new UsernamePrincipal(username); - } - return null; - } - - public boolean deletePrincipal(Principal principal) throws AccountNotFoundException - { - U user = _userMap.get(principal.getName()); - - if (user == null) - { - throw new AccountNotFoundException(principal.getName()); - } - - try - { - _userUpdate.lock(); - user.delete(); - - try - { - savePasswordFile(); - } - catch (IOException e) - { - getLogger().error("Unable to remove user '" + user.getName() + "' from password file."); - return false; - } - - _userMap.remove(user.getName()); - } - finally - { - _userUpdate.unlock(); - } - - return true; - } - - public boolean createPrincipal(Principal principal, char[] password) - { - if (_userMap.get(principal.getName()) != null) - { - return false; - } - - U user = createUserFromPassword(principal, password); - - - try - { - _userUpdate.lock(); - _userMap.put(user.getName(), user); - - try - { - savePasswordFile(); - return true; - } - catch (IOException e) - { - //remove the use on failure. - _userMap.remove(user.getName()); - return false; - } - } - finally - { - _userUpdate.unlock(); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java deleted file mode 100644 index 4f3892c2c6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.database; - -import java.security.Principal; -import java.util.HashMap; -import java.util.Map; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.login.AccountNotFoundException; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5HashedInitialiser; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5HashedSaslServer; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5HexInitialiser; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5HexSaslServer; - -/** - * Represents a user database where the account information is stored in a simple flat file. - * - * The file is expected to be in the form: username:password username1:password1 ... usernamen:passwordn - * - * where a carriage return separates each username/password pair. Passwords are assumed to be in plain text. - */ -public class Base64MD5PasswordFilePrincipalDatabase extends AbstractPasswordFilePrincipalDatabase<HashedUser> -{ - private final Logger _logger = Logger.getLogger(Base64MD5PasswordFilePrincipalDatabase.class); - private String _mechanismsString; - private final Map<String, CallbackHandler> _callbackHandlerMap = new HashMap<String, CallbackHandler>(); - - public Base64MD5PasswordFilePrincipalDatabase() - { - CRAMMD5HashedInitialiser crammd5HashedInitialiser = new CRAMMD5HashedInitialiser(); - crammd5HashedInitialiser.initialise(this); - _callbackHandlerMap.put(CRAMMD5HashedSaslServer.MECHANISM, crammd5HashedInitialiser.getCallbackHandler()); - - CRAMMD5HexInitialiser crammd5HexInitialiser = new CRAMMD5HexInitialiser(); - crammd5HexInitialiser.initialise(this); - _callbackHandlerMap.put(CRAMMD5HexSaslServer.MECHANISM, crammd5HexInitialiser.getCallbackHandler()); - - _mechanismsString = CRAMMD5HashedSaslServer.MECHANISM + " " + CRAMMD5HexSaslServer.MECHANISM; - } - - - /** - * Used to verify that the presented Password is correct. Currently only used by Management Console - * - * @param principal The principal to authenticate - * @param password The password to check - * - * @return true if password is correct - * - * @throws AccountNotFoundException if the principal cannot be found - */ - public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException - { - char[] pwd = lookupPassword(principal); - - if (pwd == null) - { - throw new AccountNotFoundException("Unable to lookup the specfied users password"); - } - - byte[] byteArray = new byte[password.length]; - int index = 0; - for (char c : password) - { - byteArray[index++] = (byte) c; - } - - byte[] MD5byteArray; - try - { - MD5byteArray = HashedUser.getMD5(byteArray); - } - catch (Exception e1) - { - getLogger().warn("Unable to hash password for user '" + principal + "' for comparison"); - return false; - } - - char[] hashedPassword = new char[MD5byteArray.length]; - - index = 0; - for (byte c : MD5byteArray) - { - hashedPassword[index++] = (char) c; - } - - return compareCharArray(pwd, hashedPassword); - } - - protected HashedUser createUserFromPassword(Principal principal, char[] passwd) - { - return new HashedUser(principal.getName(), passwd); - } - - - protected HashedUser createUserFromFileData(String[] result) - { - return new HashedUser(result); - } - - protected Logger getLogger() - { - return _logger; - } - - @Override - public String getMechanisms() - { - return _mechanismsString; - } - - @Override - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - CallbackHandler callbackHandler = _callbackHandlerMap.get(mechanism); - if(callbackHandler == null) - { - throw new SaslException("Unsupported mechanism: " + mechanism); - } - - //The SaslServers simply delegate to the built in CRAM-MD5 SaslServer - if(CRAMMD5HashedSaslServer.MECHANISM.equals(mechanism)) - { - return new CRAMMD5HashedSaslServer(mechanism, "AMQP", localFQDN, null, callbackHandler); - } - else if(CRAMMD5HexSaslServer.MECHANISM.equals(mechanism)) - { - return new CRAMMD5HexSaslServer(mechanism, "AMQP", localFQDN, null, callbackHandler); - } - - throw new SaslException("Unsupported mechanism: " + mechanism); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/HashedUser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/HashedUser.java deleted file mode 100644 index b9de1587b5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/HashedUser.java +++ /dev/null @@ -1,194 +0,0 @@ -/* -* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.database; - -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; - -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - - -public class HashedUser implements PasswordPrincipal -{ - private static final Logger _logger = Logger.getLogger(HashedUser.class); - - private String _name; - private char[] _password; - private byte[] _encodedPassword = null; - private boolean _modified = false; - private boolean _deleted = false; - - HashedUser(String[] data) - { - if (data.length != 2) - { - throw new IllegalArgumentException("User Data should be length 2, username, password"); - } - - _name = data[0]; - - byte[] encoded_password; - try - { - encoded_password = data[1].getBytes(Base64MD5PasswordFilePrincipalDatabase.DEFAULT_ENCODING); - } - catch (UnsupportedEncodingException e) - { - throw new RuntimeException("MD5 encoding not supported, even though the Java standard requires it",e); - } - - Base64 b64 = new Base64(); - byte[] decoded = b64.decode(encoded_password); - - _encodedPassword = encoded_password; - - _password = new char[decoded.length]; - - int index = 0; - for (byte c : decoded) - { - _password[index++] = (char) c; - } - } - - public HashedUser(String name, char[] password) - { - _name = name; - setPassword(password,false); - } - - public static byte[] getMD5(byte[] data) - { - MessageDigest md = null; - try - { - md = MessageDigest.getInstance("MD5"); - } - catch (NoSuchAlgorithmException e) - { - throw new RuntimeException("MD5 not supported although Java compliance requires it"); - } - - for (byte b : data) - { - md.update(b); - } - - return md.digest(); - } - - public String getName() - { - return _name; - } - - public String toString() - { - return _name; - } - - public char[] getPassword() - { - return _password; - } - - public void setPassword(char[] password) - { - setPassword(password, false); - } - - public void restorePassword(char[] password) - { - setPassword(password, true); - } - - void setPassword(char[] password, boolean alreadyHashed) - { - if(alreadyHashed){ - _password = password; - } - else - { - byte[] byteArray = new byte[password.length]; - int index = 0; - for (char c : password) - { - byteArray[index++] = (byte) c; - } - - byte[] MD5byteArray = getMD5(byteArray); - - _password = new char[MD5byteArray.length]; - - index = 0; - for (byte c : MD5byteArray) - { - _password[index++] = (char) c; - } - } - - _modified = true; - _encodedPassword = null; - } - - public byte[] getEncodedPassword() - { - if (_encodedPassword == null) - { - encodePassword(); - } - return _encodedPassword; - } - - private void encodePassword() - { - byte[] byteArray = new byte[_password.length]; - int index = 0; - for (char c : _password) - { - byteArray[index++] = (byte) c; - } - _encodedPassword = (new Base64()).encode(byteArray); - } - - public boolean isModified() - { - return _modified; - } - - public boolean isDeleted() - { - return _deleted; - } - - public void delete() - { - _deleted = true; - } - - public void saved() - { - _modified = false; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PasswordPrincipal.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PasswordPrincipal.java deleted file mode 100644 index 8e12d5f0a3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PasswordPrincipal.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.database; - -import java.security.Principal; - -interface PasswordPrincipal extends Principal -{ - char[] getPassword(); - byte[] getEncodedPassword(); - - void setPassword(char[] password); - void restorePassword(char[] password); - - boolean isDeleted(); - - boolean isModified(); - - void saved(); - - void delete(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java deleted file mode 100644 index 34d2710472..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.database; - -import java.security.Principal; -import java.util.HashMap; -import java.util.Map; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.login.AccountNotFoundException; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.security.auth.sasl.amqplain.AmqPlainInitialiser; -import org.apache.qpid.server.security.auth.sasl.amqplain.AmqPlainSaslServer; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5Initialiser; -import org.apache.qpid.server.security.auth.sasl.plain.PlainInitialiser; -import org.apache.qpid.server.security.auth.sasl.plain.PlainSaslServer; - -/** - * Represents a user database where the account information is stored in a simple flat file. - * - * The file is expected to be in the form: username:password username1:password1 ... usernamen:passwordn - * - * where a carriage return separates each username/password pair. Passwords are assumed to be in plain text. - */ -public class PlainPasswordFilePrincipalDatabase extends AbstractPasswordFilePrincipalDatabase<PlainUser> -{ - - private final Logger _logger = Logger.getLogger(PlainPasswordFilePrincipalDatabase.class); - private final Map<String, CallbackHandler> _callbackHandlerMap = new HashMap<String, CallbackHandler>(); - private String _mechanismsString; - - public PlainPasswordFilePrincipalDatabase() - { - AmqPlainInitialiser amqPlainInitialiser = new AmqPlainInitialiser(); - amqPlainInitialiser.initialise(this); - _callbackHandlerMap.put(AmqPlainSaslServer.MECHANISM, amqPlainInitialiser.getCallbackHandler()); - - PlainInitialiser plainInitialiser = new PlainInitialiser(); - plainInitialiser.initialise(this); - _callbackHandlerMap.put(PlainSaslServer.MECHANISM, plainInitialiser.getCallbackHandler()); - - CRAMMD5Initialiser crammd5Initialiser = new CRAMMD5Initialiser(); - crammd5Initialiser.initialise(this); - _callbackHandlerMap.put(CRAMMD5Initialiser.MECHANISM, crammd5Initialiser.getCallbackHandler()); - - _mechanismsString = AmqPlainSaslServer.MECHANISM + " " + PlainSaslServer.MECHANISM + " " + CRAMMD5Initialiser.MECHANISM; - } - - - /** - * Used to verify that the presented Password is correct. Currently only used by Management Console - * - * @param principal The principal to authenticate - * @param password The plaintext password to check - * - * @return true if password is correct - * - * @throws AccountNotFoundException if the principal cannot be found - */ - public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException - { - - char[] pwd = lookupPassword(principal); - - if (pwd == null) - { - throw new AccountNotFoundException("Unable to lookup the specfied users password"); - } - - return compareCharArray(pwd, password); - - } - - protected PlainUser createUserFromPassword(Principal principal, char[] passwd) - { - return new PlainUser(principal.getName(), passwd); - } - - - @Override - protected PlainUser createUserFromFileData(String[] result) - { - return new PlainUser(result); - } - - - protected Logger getLogger() - { - return _logger; - } - - - @Override - public String getMechanisms() - { - return _mechanismsString; - } - - @Override - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - CallbackHandler callbackHandler = _callbackHandlerMap.get(mechanism); - if(callbackHandler == null) - { - throw new SaslException("Unsupported mechanism: " + mechanism); - } - - if(CRAMMD5Initialiser.MECHANISM.equals(mechanism)) - { - //simply delegate to the built in CRAM-MD5 SaslServer - return Sasl.createSaslServer(mechanism, "AMQP", localFQDN, null, callbackHandler); - } - else if(PlainSaslServer.MECHANISM.equals(mechanism)) - { - return new PlainSaslServer(callbackHandler); - } - else if(AmqPlainSaslServer.MECHANISM.equals(mechanism)) - { - return new AmqPlainSaslServer(callbackHandler); - } - - throw new SaslException("Unsupported mechanism: " + mechanism); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainUser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainUser.java deleted file mode 100644 index bf9bfc6c99..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainUser.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.database; - -public class PlainUser implements PasswordPrincipal -{ - private String _name; - private char[] _password; - private boolean _modified = false; - private boolean _deleted = false; - - PlainUser(String[] data) - { - if (data.length != 2) - { - throw new IllegalArgumentException("User Data should be length 2, username, password"); - } - - _name = data[0]; - - _password = data[1].toCharArray(); - - } - - public PlainUser(String name, char[] password) - { - _name = name; - _password = password; - _modified = true; - } - - public String getName() - { - return _name; - } - - public String toString() - { - return _name; - } - - public char[] getPassword() - { - return _password; - } - - public byte[] getEncodedPassword() - { - byte[] byteArray = new byte[_password.length]; - int index = 0; - for (char c : _password) - { - byteArray[index++] = (byte) c; - } - return byteArray; - } - - - - public void restorePassword(char[] password) - { - setPassword(password); - } - - public void setPassword(char[] password) - { - _password = password; - _modified = true; - } - - public boolean isModified() - { - return _modified; - } - - public boolean isDeleted() - { - return _deleted; - } - - public void delete() - { - _deleted = true; - } - - public void saved() - { - _modified = false; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java deleted file mode 100644 index 7e3e28e4f8..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.database; - -import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser; - -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.login.AccountNotFoundException; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import java.io.File; -import java.io.IOException; -import java.security.Principal; -import java.util.List; -import java.util.Map; - -/** Represents a "user database" which is really a way of storing principals (i.e. usernames) and passwords. */ -public interface PrincipalDatabase -{ - void open(File passwordFile) throws IOException; - - /** - * Set the password for a given principal in the specified callback. This is used for certain SASL providers. The - * user database implementation should look up the password in any way it chooses and set it in the callback by - * calling its setPassword method. - * - * @param principal the principal - * @param callback the password callback that wants to receive the password - * - * @throws AccountNotFoundException if the account for specified principal could not be found - * @throws IOException if there was an error looking up the principal - */ - void setPassword(Principal principal, PasswordCallback callback) - throws IOException, AccountNotFoundException; - - /** - * Used to verify that the presented Password is correct. Currently only used by Management Console - * @param principal The principal to authenticate - * @param password The password to check - * @return true if password is correct - * @throws AccountNotFoundException if the principal cannot be found - */ - boolean verifyPassword(String principal, char[] password) - throws AccountNotFoundException; - - /** - * Update(Change) the password for the given principal - * @param principal Who's password is to be changed - * @param password The new password to use - * @return True if change was successful - * @throws AccountNotFoundException If the given principal doesn't exist in the Database - */ - boolean updatePassword(Principal principal, char[] password) - throws AccountNotFoundException; - - /** - * Create a new principal in the database - * @param principal The principal to create - * @param password The password to set for the principal - * @return True on a successful creation - */ - boolean createPrincipal(Principal principal, char[] password); - - /** - * Delete a principal - * @param principal The principal to delete - * @return True on a successful creation - * @throws AccountNotFoundException If the given principal doesn't exist in the Database - */ - boolean deletePrincipal(Principal principal) - throws AccountNotFoundException; - - /** - * Get the principal from the database with the given username - * @param username of the principal to lookup - * @return The Principal object for the given username or null if not found. - */ - Principal getUser(String username); - - /** - * Reload the database to its ensure contents are up to date - * @throws IOException If there was an error reloading the database - */ - void reload() throws IOException; - - List<Principal> getUsers(); - - /** - * Get the list of mechanisms supported for use with the PrincipalDatabase - * @return space separated list of supported Sasl mechanisms - */ - public String getMechanisms(); - - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/jmx/JMXPasswordAuthenticator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/jmx/JMXPasswordAuthenticator.java deleted file mode 100644 index bf8d489e61..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/jmx/JMXPasswordAuthenticator.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.jmx; - -import java.net.SocketAddress; - -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.security.SubjectCreator; -import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; -import org.apache.qpid.server.security.auth.SubjectAuthenticationResult; - -import javax.management.remote.JMXAuthenticator; -import javax.security.auth.Subject; - -public class JMXPasswordAuthenticator implements JMXAuthenticator -{ - static final String UNABLE_TO_LOOKUP = "The broker was unable to lookup the user details"; - static final String SHOULD_BE_STRING_ARRAY = "User details should be String[]"; - static final String SHOULD_HAVE_2_ELEMENTS = "User details should have 2 elements, username, password"; - static final String SHOULD_BE_NON_NULL = "Supplied username and password should be non-null"; - static final String INVALID_CREDENTIALS = "Invalid user details supplied"; - static final String USER_NOT_AUTHORISED_FOR_MANAGEMENT = "User not authorised for management"; - static final String CREDENTIALS_REQUIRED = "User details are required. " + - "Please ensure you are using an up to date management console to connect."; - - private final Broker _broker; - private final SocketAddress _address; - - public JMXPasswordAuthenticator(Broker broker, SocketAddress address) - { - _broker = broker; - _address = address; - } - - public Subject authenticate(Object credentials) throws SecurityException - { - validateCredentials(credentials); - - final String[] userCredentials = (String[]) credentials; - final String username = (String) userCredentials[0]; - final String password = (String) userCredentials[1]; - - final Subject authenticatedSubject = doAuthentication(username, password); - doManagementAuthorisation(authenticatedSubject); - return authenticatedSubject; - } - - private void validateCredentials(Object credentials) - { - // Verify that credential's are of type String[]. - if (!(credentials instanceof String[])) - { - if (credentials == null) - { - throw new SecurityException(CREDENTIALS_REQUIRED); - } - else - { - throw new SecurityException(SHOULD_BE_STRING_ARRAY); - } - } - - // Verify that required number of credentials. - if (((String[])credentials).length != 2) - { - throw new SecurityException(SHOULD_HAVE_2_ELEMENTS); - } - } - - private Subject doAuthentication(final String username, final String password) - { - // Verify that all required credentials are actually present. - if (username == null || password == null) - { - throw new SecurityException(SHOULD_BE_NON_NULL); - } - - SubjectCreator subjectCreator = _broker.getSubjectCreator(_address); - if (subjectCreator == null) - { - throw new SecurityException("Can't get subject creator for " + _address); - } - - final SubjectAuthenticationResult result = subjectCreator.authenticate(username, password); - - if (AuthenticationStatus.ERROR.equals(result.getStatus())) - { - throw new SecurityException("Authentication manager failed", result.getCause()); - } - else if (AuthenticationStatus.SUCCESS.equals(result.getStatus())) - { - return result.getSubject(); - } - else - { - throw new SecurityException(INVALID_CREDENTIALS); - } - } - - private void doManagementAuthorisation(Subject authenticatedSubject) - { - SecurityManager.setThreadSubject(authenticatedSubject); - try - { - if (!_broker.getSecurityManager().accessManagement()) - { - throw new SecurityException(USER_NOT_AUTHORISED_FOR_MANAGEMENT); - } - } - finally - { - SecurityManager.setThreadSubject(null); - } - } - - -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java deleted file mode 100644 index 5d427c4afb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; - -/** - * Factory for {@link PrincipalDatabaseAuthenticationManager} objects configured - * with either the Plain or Base64MD5 digest {@link PrincipalDatabase} - * implementation. - */ -public abstract class AbstractPrincipalDatabaseAuthManagerFactory implements AuthenticationManagerFactory -{ - public static final String RESOURCE_BUNDLE = "org.apache.qpid.server.security.auth.manager.PasswordFileAuthenticationProviderAttributeDescriptions"; - public static final String ATTRIBUTE_PATH = "path"; - - private static final Logger LOGGER = Logger.getLogger(AbstractPrincipalDatabaseAuthManagerFactory.class); - - public static final Collection<String> ATTRIBUTES = Collections.unmodifiableList(Arrays.asList( - ATTRIBUTE_TYPE, - ATTRIBUTE_PATH)); - - - @Override - public AuthenticationManager createInstance(Map<String, Object> attributes) - { - if (attributes == null || !getType().equals(attributes.get(ATTRIBUTE_TYPE))) - { - return null; - } - - String passwordFile = (String) attributes.get(ATTRIBUTE_PATH); - if (passwordFile == null) - { - LOGGER.warn("Password file path must not be null"); - return null; - } - - PrincipalDatabase principalDatabase = createPrincipalDatabase(); - return new PrincipalDatabaseAuthenticationManager(principalDatabase, passwordFile); - } - - abstract PrincipalDatabase createPrincipalDatabase(); - - @Override - public Collection<String> getAttributeNames() - { - return ATTRIBUTES; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java deleted file mode 100644 index 30626ce98c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.security.Principal; - -import javax.security.auth.Subject; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.sasl.anonymous.AnonymousSaslServer; - -public class AnonymousAuthenticationManager implements AuthenticationManager -{ - private static final String ANONYMOUS = "ANONYMOUS"; - - public static final String ANONYMOUS_USERNAME = "ANONYMOUS"; - - public static final Principal ANONYMOUS_PRINCIPAL = new UsernamePrincipal(ANONYMOUS_USERNAME); - - public static final Subject ANONYMOUS_SUBJECT = new Subject(); - static - { - ANONYMOUS_SUBJECT.getPrincipals().add(ANONYMOUS_PRINCIPAL); - } - - private static final AuthenticationResult ANONYMOUS_AUTHENTICATION = new AuthenticationResult(ANONYMOUS_PRINCIPAL); - - static final AnonymousAuthenticationManager INSTANCE = new AnonymousAuthenticationManager(); - - AnonymousAuthenticationManager() - { - } - - @Override - public void initialise() - { - - } - - @Override - public String getMechanisms() - { - return ANONYMOUS; - } - - @Override - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - if(ANONYMOUS.equals(mechanism)) - { - return new AnonymousSaslServer(); - } - else - { - throw new SaslException("Unknown mechanism: " + mechanism); - } - } - - @Override - public AuthenticationResult authenticate(SaslServer server, byte[] response) - { - try - { - // Process response from the client - byte[] challenge = server.evaluateResponse(response != null ? response : new byte[0]); - - if (server.isComplete()) - { - return ANONYMOUS_AUTHENTICATION; - } - else - { - return new AuthenticationResult(challenge, AuthenticationResult.AuthenticationStatus.CONTINUE); - } - } - catch (SaslException e) - { - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e); - } - } - - @Override - public AuthenticationResult authenticate(String username, String password) - { - return ANONYMOUS_AUTHENTICATION; - } - - @Override - public void close() - { - } - - @Override - public void onCreate() - { - // nothing to do, no external resource is required - } - - @Override - public void onDelete() - { - // nothing to do, no external resource is used - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java deleted file mode 100644 index 91aba71720..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; - -public class AnonymousAuthenticationManagerFactory implements AuthenticationManagerFactory -{ - public static final String PROVIDER_TYPE = "Anonymous"; - - @Override - public AuthenticationManager createInstance(Map<String, Object> attributes) - { - if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE))) - { - return new AnonymousAuthenticationManager(); - } - return null; - } - - @Override - public Collection<String> getAttributeNames() - { - return Collections.<String>singletonList(ATTRIBUTE_TYPE); - } - - @Override - public String getType() - { - return PROVIDER_TYPE; - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return null; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java deleted file mode 100644 index 67a4f348b1..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.security.Principal; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import org.apache.qpid.common.Closeable; -import org.apache.qpid.server.security.auth.AuthenticationResult; - -/** - * Implementations of the AuthenticationManager are responsible for determining - * the authenticity of a user's credentials. - * <p> - * If the authentication is successful, the manager is responsible for producing an - * {@link AuthenticationResult} containing the user's main {@link Principal} and zero or - * more other implementation-specific principals. - * </p> - */ -public interface AuthenticationManager extends Closeable -{ - /** - * Initialise the authentication plugin. - * - */ - void initialise(); - - /** - * Gets the SASL mechanisms known to this manager. - * - * @return SASL mechanism names, space separated. - */ - String getMechanisms(); - - /** - * Creates a SASL server for the specified mechanism name for the given - * fully qualified domain name. - * - * @param mechanism mechanism name - * @param localFQDN domain name - * @param externalPrincipal externally authenticated Principal - * @return SASL server - * @throws SaslException - */ - SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException; - - /** - * Authenticates a user using SASL negotiation. - * - * @param server SASL server - * @param response SASL response to process - * - * @return authentication result - */ - AuthenticationResult authenticate(SaslServer server, byte[] response); - - /** - * Authenticates a user using their username and password. - * - * @param username username - * @param password password - * - * @return authentication result - */ - AuthenticationResult authenticate(String username, String password); - - /** - * Called after manager creation to create the required resources, for example, user databases etc. - */ - void onCreate(); - - /** - * Called before manager deletion to release and clean the resources created in {@link #onCreate()}. - */ - void onDelete(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java deleted file mode 100644 index 8b979c324d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.util.Map; - -import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; -import org.apache.qpid.server.util.ResourceBundleLoader; - -public class Base64MD5PasswordFileAuthenticationManagerFactory extends AbstractPrincipalDatabaseAuthManagerFactory -{ - public static final String PROVIDER_TYPE = "Base64MD5PasswordFile"; - - @Override - public String getType() - { - return PROVIDER_TYPE; - } - - @Override - PrincipalDatabase createPrincipalDatabase() - { - return new Base64MD5PasswordFilePrincipalDatabase(); - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return ResourceBundleLoader.getResources(RESOURCE_BUNDLE); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java deleted file mode 100644 index c503549bf2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.security.Principal; - -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.sasl.external.ExternalSaslServer; - -public class ExternalAuthenticationManager implements AuthenticationManager -{ - private static final String EXTERNAL = "EXTERNAL"; - - private boolean _useFullDN = false; - - ExternalAuthenticationManager(boolean useFullDN) - { - _useFullDN = useFullDN; - } - - @Override - public void initialise() - { - - } - - @Override - public String getMechanisms() - { - return EXTERNAL; - } - - @Override - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - if(EXTERNAL.equals(mechanism)) - { - return new ExternalSaslServer(externalPrincipal, _useFullDN); - } - else - { - throw new SaslException("Unknown mechanism: " + mechanism); - } - } - - @Override - public AuthenticationResult authenticate(SaslServer server, byte[] response) - { - // Process response from the client - try - { - server.evaluateResponse(response != null ? response : new byte[0]); - - Principal principal = ((ExternalSaslServer)server).getAuthenticatedPrincipal(); - - if(principal != null) - { - return new AuthenticationResult(principal); - } - else - { - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR); - } - } - catch (SaslException e) - { - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR,e); - } - - } - - @Override - public AuthenticationResult authenticate(String username, String password) - { - return new AuthenticationResult(new UsernamePrincipal(username)); - } - - @Override - public void close() - { - } - - @Override - public void onCreate() - { - // nothing to do, no external resource is required - } - - @Override - public void onDelete() - { - // nothing to do, no external resource is used - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java deleted file mode 100644 index 6029674cd3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; -import org.apache.qpid.server.util.ResourceBundleLoader; - -public class ExternalAuthenticationManagerFactory implements AuthenticationManagerFactory -{ - public static final String RESOURCE_BUNDLE = "org.apache.qpid.server.security.auth.manager.ExternalAuthenticationProviderAttributeDescriptions"; - public static final String PROVIDER_TYPE = "External"; - public static final String ATTRIBUTE_USE_FULL_DN = "useFullDN"; - - public static final Collection<String> ATTRIBUTES = Collections.<String> unmodifiableList(Arrays.asList( - ATTRIBUTE_TYPE, - ATTRIBUTE_USE_FULL_DN)); - - @Override - public AuthenticationManager createInstance(Map<String, Object> attributes) - { - if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE))) - { - boolean useFullDN = Boolean.valueOf(String.valueOf(attributes.get(ATTRIBUTE_USE_FULL_DN))); - - return new ExternalAuthenticationManager(useFullDN); - } - return null; - } - - @Override - public Collection<String> getAttributeNames() - { - return ATTRIBUTES; - } - - @Override - public String getType() - { - return PROVIDER_TYPE; - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return ResourceBundleLoader.getResources(RESOURCE_BUNDLE); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationProviderAttributeDescriptions.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationProviderAttributeDescriptions.properties deleted file mode 100644 index 263254e9fe..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationProviderAttributeDescriptions.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. - -useFullDN=Use the full DN as the Username
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java deleted file mode 100644 index 6bbf3ca6f5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.io.IOException; -import java.security.Principal; -import java.util.HashMap; -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.sasl.AuthorizeCallback; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.UsernamePrincipal; - -public class KerberosAuthenticationManager implements AuthenticationManager -{ - private static final String GSSAPI_MECHANISM = "GSSAPI"; - private final CallbackHandler _callbackHandler = new GssApiCallbackHandler(); - - KerberosAuthenticationManager() - { - } - - @Override - public void initialise() - { - - } - - @Override - public String getMechanisms() - { - return GSSAPI_MECHANISM; - } - - @Override - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - if(GSSAPI_MECHANISM.equals(mechanism)) - { - try - { - return Sasl.createSaslServer(GSSAPI_MECHANISM, "AMQP", localFQDN, - new HashMap<String, Object>(), _callbackHandler); - } - catch (SaslException e) - { - e.printStackTrace(System.err); - throw e; - } - } - else - { - throw new SaslException("Unknown mechanism: " + mechanism); - } - } - - @Override - public AuthenticationResult authenticate(SaslServer server, byte[] response) - { - try - { - // Process response from the client - byte[] challenge = server.evaluateResponse(response != null ? response : new byte[0]); - - if (server.isComplete()) - { - return new AuthenticationResult(new UsernamePrincipal(server.getAuthorizationID())); - } - else - { - return new AuthenticationResult(challenge, AuthenticationResult.AuthenticationStatus.CONTINUE); - } - } - catch (SaslException e) - { - e.printStackTrace(System.err); - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e); - } - } - - @Override - public AuthenticationResult authenticate(String username, String password) - { - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR); - } - - @Override - public void close() - { - } - - @Override - public void onCreate() - { - // nothing to do, no external resource is required - } - - @Override - public void onDelete() - { - // nothing to do, no external resource is used - } - - private static class GssApiCallbackHandler implements CallbackHandler - { - - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - for(Callback callback : callbacks) - { - if (callback instanceof AuthorizeCallback) - { - ((AuthorizeCallback) callback).setAuthorized(true); - } - else - { - throw new UnsupportedCallbackException(callback); - } - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java deleted file mode 100644 index a2d5bd4c8e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; - -public class KerberosAuthenticationManagerFactory implements AuthenticationManagerFactory -{ - public static final String PROVIDER_TYPE = "Kerberos"; - - @Override - public AuthenticationManager createInstance(Map<String, Object> attributes) - { - if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE))) - { - return new KerberosAuthenticationManager(); - } - return null; - } - - @Override - public Collection<String> getAttributeNames() - { - return Collections.<String>singletonList(ATTRIBUTE_TYPE); - } - - @Override - public String getType() - { - return PROVIDER_TYPE; - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return null; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PasswordFileAuthenticationProviderAttributeDescriptions.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PasswordFileAuthenticationProviderAttributeDescriptions.properties deleted file mode 100644 index e847e90f57..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PasswordFileAuthenticationProviderAttributeDescriptions.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. - -path=File location*
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java deleted file mode 100644 index 5e077cfe79..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.util.Map; - -import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; -import org.apache.qpid.server.util.ResourceBundleLoader; - -public class PlainPasswordFileAuthenticationManagerFactory extends AbstractPrincipalDatabaseAuthManagerFactory -{ - public static final String PROVIDER_TYPE = "PlainPasswordFile"; - - @Override - public String getType() - { - return PROVIDER_TYPE; - } - - @Override - PrincipalDatabase createPrincipalDatabase() - { - return new PlainPasswordFilePrincipalDatabase(); - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return ResourceBundleLoader.getResources(AbstractPrincipalDatabaseAuthManagerFactory.RESOURCE_BUNDLE); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java deleted file mode 100644 index da6464a57e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.security.Principal; - -import javax.security.auth.login.AccountNotFoundException; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; - -public class PrincipalDatabaseAuthenticationManager implements AuthenticationManager -{ - private final PrincipalDatabase _principalDatabase; - private final String _passwordFile; - - public PrincipalDatabaseAuthenticationManager(PrincipalDatabase pd, String passwordFile) - { - _principalDatabase = pd; - _passwordFile = passwordFile; - } - - public void initialise() - { - try - { - _principalDatabase.open(new File(_passwordFile)); - } - catch (FileNotFoundException e) - { - throw new IllegalConfigurationException("Exception opening password database: " + e.getMessage(), e); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot use password database at :" + _passwordFile, e); - } - } - - public String getMechanisms() - { - return _principalDatabase.getMechanisms(); - } - - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - return _principalDatabase.createSaslServer(mechanism, localFQDN, externalPrincipal); - } - - /** - * @see org.apache.qpid.server.security.auth.manager.AuthenticationManager#authenticate(SaslServer, byte[]) - */ - public AuthenticationResult authenticate(SaslServer server, byte[] response) - { - try - { - // Process response from the client - byte[] challenge = server.evaluateResponse(response != null ? response : new byte[0]); - - if (server.isComplete()) - { - final String userId = server.getAuthorizationID(); - return new AuthenticationResult(new UsernamePrincipal(userId)); - } - else - { - return new AuthenticationResult(challenge, AuthenticationResult.AuthenticationStatus.CONTINUE); - } - } - catch (SaslException e) - { - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e); - } - } - - /** - * @see org.apache.qpid.server.security.auth.manager.AuthenticationManager#authenticate(String, String) - */ - public AuthenticationResult authenticate(final String username, final String password) - { - try - { - if (_principalDatabase.verifyPassword(username, password.toCharArray())) - { - return new AuthenticationResult(new UsernamePrincipal(username)); - } - else - { - return new AuthenticationResult(AuthenticationStatus.CONTINUE); - } - } - catch (AccountNotFoundException e) - { - return new AuthenticationResult(AuthenticationStatus.CONTINUE); - } - } - - public void close() - { - - } - - public PrincipalDatabase getPrincipalDatabase() - { - return _principalDatabase; - } - - @Override - public void onCreate() - { - try - { - File passwordFile = new File(_passwordFile); - if (!passwordFile.exists()) - { - passwordFile.createNewFile(); - } - else if (!passwordFile.canRead()) - { - throw new IllegalConfigurationException("Cannot read password file" + _passwordFile + ". Check permissions."); - } - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot use password database at :" + _passwordFile, e); - } - } - - @Override - public void onDelete() - { - File file = new File(_passwordFile); - if (file.exists() && file.isFile()) - { - file.delete(); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleAuthenticationManager.java deleted file mode 100644 index 903f54dd8e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleAuthenticationManager.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.io.IOException; -import java.security.Principal; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.sasl.AuthorizeCallback; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.sasl.plain.PlainPasswordCallback; -import org.apache.qpid.server.security.auth.sasl.plain.PlainSaslServer; - -public class SimpleAuthenticationManager implements AuthenticationManager -{ - private static final Logger _logger = Logger.getLogger(SimpleAuthenticationManager.class); - - private static final String PLAIN_MECHANISM = "PLAIN"; - private static final String CRAM_MD5_MECHANISM = "CRAM-MD5"; - - private Map<String, String> _users; - - public SimpleAuthenticationManager(String userName, String userPassword) - { - this(Collections.singletonMap(userName, userPassword)); - } - - public SimpleAuthenticationManager(Map<String, String> users) - { - _users = new HashMap<String, String>(users); - } - - @Override - public void initialise() - { - } - - @Override - public String getMechanisms() - { - return PLAIN_MECHANISM + " " + CRAM_MD5_MECHANISM; - } - - @Override - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - if (PLAIN_MECHANISM.equals(mechanism)) - { - return new PlainSaslServer(new SimplePlainCallbackHandler()); - } - else if (CRAM_MD5_MECHANISM.equals(mechanism)) - { - return Sasl.createSaslServer(mechanism, "AMQP", localFQDN, null, new SimpleCramMd5CallbackHandler()); - } - else - { - throw new SaslException("Unknown mechanism: " + mechanism); - } - } - - @Override - public AuthenticationResult authenticate(SaslServer server, byte[] response) - { - try - { - // Process response from the client - byte[] challenge = server.evaluateResponse(response != null ? response : new byte[0]); - - if (server.isComplete()) - { - String authorizationID = server.getAuthorizationID(); - _logger.debug("Authenticated as " + authorizationID); - - return new AuthenticationResult(new UsernamePrincipal(authorizationID)); - } - else - { - return new AuthenticationResult(challenge, AuthenticationResult.AuthenticationStatus.CONTINUE); - } - } - catch (SaslException e) - { - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e); - } - } - - @Override - public AuthenticationResult authenticate(String username, String password) - { - if (_users.containsKey(username)) - { - String userPassword = _users.get(username); - if (userPassword.equals(password)) - { - return new AuthenticationResult(new UsernamePrincipal(username)); - } - } - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR); - } - - @Override - public void close() - { - } - - @Override - public void onCreate() - { - // nothing to do, no external resource is required - } - - @Override - public void onDelete() - { - // nothing to do, no external resource is used - } - - private class SimpleCramMd5CallbackHandler implements CallbackHandler - { - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - String username = null; - for (Callback callback : callbacks) - { - if (callback instanceof NameCallback) - { - username = ((NameCallback) callback).getDefaultName(); - } - else if (callback instanceof PasswordCallback) - { - if (_users.containsKey(username)) - { - String password = _users.get(username); - ((PasswordCallback) callback).setPassword(password.toCharArray()); - } - else - { - throw new SaslException("Authentication failed"); - } - } - else if (callback instanceof AuthorizeCallback) - { - ((AuthorizeCallback) callback).setAuthorized(true); - } - else - { - throw new UnsupportedCallbackException(callback); - } - } - } - } - - private class SimplePlainCallbackHandler implements CallbackHandler - { - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - String username = null; - for (Callback callback : callbacks) - { - if (callback instanceof NameCallback) - { - username = ((NameCallback) callback).getDefaultName(); - } - else if (callback instanceof PlainPasswordCallback) - { - if (_users.containsKey(username)) - { - PlainPasswordCallback plainPasswordCallback = (PlainPasswordCallback) callback; - String password = plainPasswordCallback.getPlainPassword(); - plainPasswordCallback.setAuthenticated(password.equals(_users.get(username))); - } - } - else if (callback instanceof AuthorizeCallback) - { - ((AuthorizeCallback) callback).setAuthorized(true); - } - else - { - throw new UnsupportedCallbackException(callback); - } - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java deleted file mode 100644 index 0db0d388d6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.io.IOException; -import java.security.Principal; -import java.util.Hashtable; - -import javax.naming.AuthenticationException; -import javax.naming.Context; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; -import javax.naming.directory.DirContext; -import javax.naming.directory.InitialDirContext; -import javax.naming.directory.SearchControls; -import javax.naming.directory.SearchResult; -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.sasl.AuthorizeCallback; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import org.apache.log4j.Logger; -import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.sasl.plain.PlainPasswordCallback; -import org.apache.qpid.server.security.auth.sasl.plain.PlainSaslServer; - -public class SimpleLDAPAuthenticationManager implements AuthenticationManager -{ - private static final Logger _logger = Logger.getLogger(SimpleLDAPAuthenticationManager.class); - - private final String _providerSearchURL; - private final String _providerAuthURL; - private final String _searchContext; - private final String _searchFilter; - private final String _ldapContextFactory; - - SimpleLDAPAuthenticationManager(String providerSearchUrl, String providerAuthUrl, String searchContext, String searchFilter, String ldapContextFactory) - { - _providerSearchURL = providerSearchUrl; - _providerAuthURL = providerAuthUrl; - _searchContext = searchContext; - _searchFilter = searchFilter; - _ldapContextFactory = ldapContextFactory; - } - - @Override - public void initialise() - { - validateInitialDirContext(); - } - - @Override - public String getMechanisms() - { - return PlainSaslServer.MECHANISM; - } - - @Override - public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException - { - if(PlainSaslServer.MECHANISM.equals(mechanism)) - { - return new PlainSaslServer(new SimpleLDAPPlainCallbackHandler()); - } - else - { - throw new SaslException("Unknown mechanism: " + mechanism); - } - } - - @Override - public AuthenticationResult authenticate(SaslServer server, byte[] response) - { - try - { - // Process response from the client - byte[] challenge = server.evaluateResponse(response != null ? response : new byte[0]); - - if (server.isComplete()) - { - String authorizationID = server.getAuthorizationID(); - _logger.debug("Authenticated as " + authorizationID); - - return new AuthenticationResult(new UsernamePrincipal(authorizationID)); - } - else - { - return new AuthenticationResult(challenge, AuthenticationResult.AuthenticationStatus.CONTINUE); - } - } - catch (SaslException e) - { - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e); - } - } - - @Override - public AuthenticationResult authenticate(String username, String password) - { - try - { - AuthenticationResult result = doLDAPNameAuthentication(getNameFromId(username), password); - if(result.getStatus() == AuthenticationStatus.SUCCESS) - { - //Return a result based on the supplied username rather than the search name - return new AuthenticationResult(new UsernamePrincipal(username)); - } - else - { - return result; - } - } - catch (NamingException e) - { - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e); - } - } - - private AuthenticationResult doLDAPNameAuthentication(String name, String password) - { - if(name == null) - { - //The search didn't return anything, class as not-authenticated before it NPEs below - return new AuthenticationResult(AuthenticationStatus.CONTINUE); - } - - Hashtable<Object,Object> env = new Hashtable<Object,Object>(); - env.put(Context.INITIAL_CONTEXT_FACTORY, _ldapContextFactory); - env.put(Context.PROVIDER_URL, _providerAuthURL); - - env.put(Context.SECURITY_AUTHENTICATION, "simple"); - - env.put(Context.SECURITY_PRINCIPAL, name); - env.put(Context.SECURITY_CREDENTIALS, password); - - DirContext ctx = null; - try - { - ctx = new InitialDirContext(env); - - //Authentication succeeded - return new AuthenticationResult(new UsernamePrincipal(name)); - } - catch(AuthenticationException ae) - { - //Authentication failed - return new AuthenticationResult(AuthenticationStatus.CONTINUE); - } - catch (NamingException e) - { - //Some other failure - return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e); - } - finally - { - if(ctx != null) - { - try - { - ctx.close(); - } - catch (Exception e) - { - _logger.warn("Exception closing InitialDirContext", e); - } - } - } - } - - @Override - public void close() - { - } - - private void validateInitialDirContext() - { - Hashtable<String,Object> env = new Hashtable<String, Object>(); - env.put(Context.INITIAL_CONTEXT_FACTORY, _ldapContextFactory); - env.put(Context.PROVIDER_URL, _providerSearchURL); - env.put(Context.SECURITY_AUTHENTICATION, "none"); - - try - { - new InitialDirContext(env).close(); - } - catch (NamingException e) - { - throw new RuntimeException("Unable to establish anonymous connection to the ldap server at " + _providerSearchURL, e); - } - } - - private class SimpleLDAPPlainCallbackHandler implements CallbackHandler - { - - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - String name = null; - String password = null; - AuthenticationResult authenticated = null; - for(Callback callback : callbacks) - { - if (callback instanceof NameCallback) - { - String id = ((NameCallback) callback).getDefaultName(); - try - { - name = getNameFromId(id); - } - catch (NamingException e) - { - _logger.warn("SASL Authentication Exception", e); - } - if(password != null) - { - authenticated = doLDAPNameAuthentication(name, password); - } - } - else if (callback instanceof PlainPasswordCallback) - { - password = ((PlainPasswordCallback)callback).getPlainPassword(); - if(name != null) - { - authenticated = doLDAPNameAuthentication(name, password); - if(authenticated.getStatus()== AuthenticationResult.AuthenticationStatus.SUCCESS) - { - ((PlainPasswordCallback)callback).setAuthenticated(true); - } - } - } - else if (callback instanceof AuthorizeCallback) - { - ((AuthorizeCallback) callback).setAuthorized(authenticated != null && authenticated.getStatus() == AuthenticationResult.AuthenticationStatus.SUCCESS); - } - else - { - throw new UnsupportedCallbackException(callback); - } - } - } - } - - private String getNameFromId(String id) throws NamingException - { - Hashtable<Object,Object> env = new Hashtable<Object,Object>(); - env.put(Context.INITIAL_CONTEXT_FACTORY, _ldapContextFactory); - env.put(Context.PROVIDER_URL, _providerSearchURL); - - env.put(Context.SECURITY_AUTHENTICATION, "none"); - DirContext ctx = null; - - ctx = new InitialDirContext(env); - - try - { - SearchControls searchControls = new SearchControls(); - searchControls.setReturningAttributes(new String[] {}); - searchControls.setCountLimit(1l); - searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); - NamingEnumeration<?> namingEnum = null; - String name = null; - - namingEnum = ctx.search(_searchContext, _searchFilter, new String[] { id }, searchControls); - if(namingEnum.hasMore()) - { - SearchResult result = (SearchResult) namingEnum.next(); - name = result.getNameInNamespace(); - } - return name; - } - finally - { - try - { - ctx.close(); - } - catch (Exception e) - { - _logger.warn("Exception closing InitialDirContext", e); - } - } - - } - - @Override - public void onCreate() - { - // nothing to do, no external resource is required - } - - @Override - public void onDelete() - { - // nothing to do, no external resource is used - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java deleted file mode 100644 index 55e90178f8..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.manager; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; -import org.apache.qpid.server.util.ResourceBundleLoader; - -public class SimpleLDAPAuthenticationManagerFactory implements AuthenticationManagerFactory -{ - public static final String RESOURCE_BUNDLE = "org.apache.qpid.server.security.auth.manager.SimpleLDAPAuthenticationProviderAttributeDescriptions"; - private static final String DEFAULT_LDAP_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory"; - - public static final String PROVIDER_TYPE = "SimpleLDAP"; - - public static final String ATTRIBUTE_LDAP_CONTEXT_FACTORY = "ldapContextFactory"; - public static final String ATTRIBUTE_SEARCH_FILTER = "searchFilter"; - public static final String ATTRIBUTE_SEARCH_CONTEXT = "searchContext"; - public static final String ATTRIBUTE_PROVIDER_AUTH_URL = "providerAuthUrl"; - public static final String ATTRIBUTE_PROVIDER_URL = "providerUrl"; - - public static final Collection<String> ATTRIBUTES = Collections.<String> unmodifiableList(Arrays.asList( - ATTRIBUTE_TYPE, - ATTRIBUTE_PROVIDER_URL, - ATTRIBUTE_SEARCH_CONTEXT, - ATTRIBUTE_SEARCH_FILTER, - ATTRIBUTE_PROVIDER_AUTH_URL, - ATTRIBUTE_LDAP_CONTEXT_FACTORY - )); - - @Override - public AuthenticationManager createInstance(Map<String, Object> attributes) - { - if (attributes == null || !PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE))) - { - return null; - } - String providerUrl = (String) attributes.get(ATTRIBUTE_PROVIDER_URL); - String providerAuthUrl = (String) attributes.get(ATTRIBUTE_PROVIDER_AUTH_URL); - if (providerAuthUrl == null) - { - providerAuthUrl = providerUrl; - } - String searchContext = (String) attributes.get(ATTRIBUTE_SEARCH_CONTEXT); - String searchFilter = (String) attributes.get(ATTRIBUTE_SEARCH_FILTER); - String ldapContextFactory = (String) attributes.get(ATTRIBUTE_LDAP_CONTEXT_FACTORY); - if (ldapContextFactory == null) - { - ldapContextFactory = DEFAULT_LDAP_CONTEXT_FACTORY; - } - - return new SimpleLDAPAuthenticationManager(providerUrl, providerAuthUrl, searchContext, searchFilter, - ldapContextFactory); - } - - @Override - public Collection<String> getAttributeNames() - { - return ATTRIBUTES; - } - - @Override - public String getType() - { - return PROVIDER_TYPE; - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return ResourceBundleLoader.getResources(RESOURCE_BUNDLE); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationProviderAttributeDescriptions.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationProviderAttributeDescriptions.properties deleted file mode 100644 index 5439c7fff5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationProviderAttributeDescriptions.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. - -ldapContextFactory= LDAP context factory -searchFilter=Search filter* -searchContext=Search context* -providerAuthUrl=LDAP authentication URL -providerUrl=LDAP server URL*
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/AuthenticationProviderInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/AuthenticationProviderInitialiser.java deleted file mode 100644 index 4cbf5096df..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/AuthenticationProviderInitialiser.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl; - -import javax.security.auth.callback.CallbackHandler; - -public interface AuthenticationProviderInitialiser -{ - /** - * @return the mechanism's name. This will be used in the list of mechanism's advertised to the - * client. - */ - String getMechanismName(); - - /** - * @return the callback handler that should be used to process authentication requests for this mechanism. This will - * be called after initialise and will be stored by the authentication manager. The callback handler <b>must</b> be - * fully threadsafe. - */ - CallbackHandler getCallbackHandler(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java deleted file mode 100644 index f36ef1516c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl; - -import org.apache.log4j.Logger; - -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.auth.login.AccountNotFoundException; -import javax.security.sasl.AuthorizeCallback; -import java.io.IOException; -import java.security.Principal; - -public abstract class UsernamePasswordInitialiser implements AuthenticationProviderInitialiser -{ - protected static final Logger _logger = Logger.getLogger(UsernamePasswordInitialiser.class); - - private ServerCallbackHandler _callbackHandler; - - private static class ServerCallbackHandler implements CallbackHandler - { - private final PrincipalDatabase _principalDatabase; - - protected ServerCallbackHandler(PrincipalDatabase database) - { - _principalDatabase = database; - } - - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - Principal username = null; - for (Callback callback : callbacks) - { - if (callback instanceof NameCallback) - { - username = new UsernamePrincipal(((NameCallback) callback).getDefaultName()); - } - else if (callback instanceof PasswordCallback) - { - try - { - _principalDatabase.setPassword(username, (PasswordCallback) callback); - } - catch (AccountNotFoundException e) - { - // very annoyingly the callback handler does not throw anything more appropriate than - // IOException - IOException ioe = new IOException("Error looking up user " + e); - ioe.initCause(e); - throw ioe; - } - } - else if (callback instanceof AuthorizeCallback) - { - ((AuthorizeCallback) callback).setAuthorized(true); - } - else - { - throw new UnsupportedCallbackException(callback); - } - } - } - } - - public void initialise(PrincipalDatabase db) - { - if (db == null) - { - throw new NullPointerException("Cannot initialise with a null Principal database."); - } - - _callbackHandler = new ServerCallbackHandler(db); - } - - public CallbackHandler getCallbackHandler() - { - return _callbackHandler; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainInitialiser.java deleted file mode 100644 index 8f8686db88..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainInitialiser.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.amqplain; - -import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser; - -public class AmqPlainInitialiser extends UsernamePasswordInitialiser -{ - public String getMechanismName() - { - return "AMQPLAIN"; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainSaslServer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainSaslServer.java deleted file mode 100644 index a4c4fff42f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainSaslServer.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.amqplain; - -import org.apache.qpid.framing.AMQFrameDecodingException; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.framing.FieldTableFactory; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.sasl.AuthorizeCallback; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; - -public class AmqPlainSaslServer implements SaslServer -{ - public static final String MECHANISM = "AMQPLAIN"; - - private CallbackHandler _cbh; - - private String _authorizationId; - - private boolean _complete = false; - - public AmqPlainSaslServer(CallbackHandler cbh) - { - _cbh = cbh; - } - - public String getMechanismName() - { - return MECHANISM; - } - - public byte[] evaluateResponse(byte[] response) throws SaslException - { - try - { - final FieldTable ft = FieldTableFactory.newFieldTable(new DataInputStream(new ByteArrayInputStream(response)), response.length); - String username = ft.getString("LOGIN"); - // we do not care about the prompt but it throws if null - NameCallback nameCb = new NameCallback("prompt", username); - // we do not care about the prompt but it throws if null - PasswordCallback passwordCb = new PasswordCallback("prompt", false); - // TODO: should not get pwd as a String but as a char array... - String pwd = ft.getString("PASSWORD"); - AuthorizeCallback authzCb = new AuthorizeCallback(username, username); - Callback[] callbacks = new Callback[]{nameCb, passwordCb, authzCb}; - _cbh.handle(callbacks); - String storedPwd = new String(passwordCb.getPassword()); - if (storedPwd.equals(pwd)) - { - _complete = true; - } - if (authzCb.isAuthorized() && _complete) - { - _authorizationId = authzCb.getAuthenticationID(); - return null; - } - else - { - throw new SaslException("Authentication failed"); - } - } - catch (AMQFrameDecodingException e) - { - throw new SaslException("Unable to decode response: " + e, e); - } - catch (IOException e) - { - throw new SaslException("Error processing data: " + e, e); - } - catch (UnsupportedCallbackException e) - { - throw new SaslException("Unable to obtain data from callback handler: " + e, e); - } - } - - public boolean isComplete() - { - return _complete; - } - - public String getAuthorizationID() - { - return _authorizationId; - } - - public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException - { - throw new SaslException("Unsupported operation"); - } - - public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException - { - throw new SaslException("Unsupported operation"); - } - - public Object getNegotiatedProperty(String propName) - { - return null; - } - - public void dispose() throws SaslException - { - _cbh = null; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainSaslServerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainSaslServerFactory.java deleted file mode 100644 index 3a73f577fe..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/amqplain/AmqPlainSaslServerFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.amqplain; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import javax.security.sasl.SaslServerFactory; -import java.util.Map; - -public class AmqPlainSaslServerFactory implements SaslServerFactory -{ - public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map props, - CallbackHandler cbh) throws SaslException - { - if (AmqPlainSaslServer.MECHANISM.equals(mechanism)) - { - return new AmqPlainSaslServer(cbh); - } - else - { - return null; - } - } - - public String[] getMechanismNames(Map props) - { - if (props != null && - (props.containsKey(Sasl.POLICY_NOPLAINTEXT) || - props.containsKey(Sasl.POLICY_NODICTIONARY) || - props.containsKey(Sasl.POLICY_NOACTIVE))) - { - // returned array must be non null according to interface documentation - return new String[0]; - } - else - { - return new String[]{AmqPlainSaslServer.MECHANISM}; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServer.java deleted file mode 100644 index d10193e743..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServer.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.anonymous; - -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager; - - -public class AnonymousSaslServer implements SaslServer -{ - public static final String MECHANISM = "ANONYMOUS"; - - private boolean _complete = false; - - public AnonymousSaslServer() - { - } - - public String getMechanismName() - { - return MECHANISM; - } - - public byte[] evaluateResponse(byte[] response) throws SaslException - { - _complete = true; - return null; - } - - public boolean isComplete() - { - return _complete; - } - - public String getAuthorizationID() - { - return AnonymousAuthenticationManager.ANONYMOUS_PRINCIPAL.getName(); - } - - public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException - { - throw new SaslException("Unsupported operation"); - } - - public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException - { - throw new SaslException("Unsupported operation"); - } - - public Object getNegotiatedProperty(String propName) - { - return null; - } - - public void dispose() throws SaslException - { - } -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServerFactory.java deleted file mode 100644 index 4650234972..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServerFactory.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.anonymous; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import javax.security.sasl.SaslServerFactory; -import java.util.Map; - -public class AnonymousSaslServerFactory implements SaslServerFactory -{ - public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map props, - CallbackHandler cbh) throws SaslException - { - if (AnonymousSaslServer.MECHANISM.equals(mechanism)) - { - return new AnonymousSaslServer(); - } - else - { - return null; - } - } - - public String[] getMechanismNames(Map props) - { - if (props != null && - (props.containsKey(Sasl.POLICY_NOPLAINTEXT) || - props.containsKey(Sasl.POLICY_NODICTIONARY) || - props.containsKey(Sasl.POLICY_NOACTIVE) || - props.containsKey(Sasl.POLICY_NOANONYMOUS))) - { - // returned array must be non null according to interface documentation - return new String[0]; - } - else - { - return new String[]{AnonymousSaslServer.MECHANISM}; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedInitialiser.java deleted file mode 100644 index fc324b686a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedInitialiser.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.crammd5; - -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; -import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser; - -public class CRAMMD5HashedInitialiser extends UsernamePasswordInitialiser -{ - public String getMechanismName() - { - return CRAMMD5HashedSaslServer.MECHANISM; - } - - public void initialise(PrincipalDatabase passwordFile) - { - super.initialise(passwordFile); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedSaslServer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedSaslServer.java deleted file mode 100644 index a2d9fa5e3e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedSaslServer.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.crammd5; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import javax.security.sasl.SaslServerFactory; -import java.util.Enumeration; -import java.util.Map; - -public class CRAMMD5HashedSaslServer implements SaslServer -{ - public static final String MECHANISM = "CRAM-MD5-HASHED"; - - private SaslServer _realServer; - - public CRAMMD5HashedSaslServer(String mechanism, String protocol, String serverName, Map<String, ?> props, - CallbackHandler cbh) throws SaslException - { - Enumeration factories = Sasl.getSaslServerFactories(); - - while (factories.hasMoreElements()) - { - SaslServerFactory factory = (SaslServerFactory) factories.nextElement(); - - if (factory instanceof CRAMMD5HashedServerFactory) - { - continue; - } - - String[] mechs = factory.getMechanismNames(props); - - for (String mech : mechs) - { - if (mech.equals("CRAM-MD5")) - { - _realServer = factory.createSaslServer("CRAM-MD5", protocol, serverName, props, cbh); - return; - } - } - } - - throw new RuntimeException("No default SaslServer found for mechanism:" + "CRAM-MD5"); - } - - public String getMechanismName() - { - return MECHANISM; - } - - public byte[] evaluateResponse(byte[] response) throws SaslException - { - return _realServer.evaluateResponse(response); - } - - public boolean isComplete() - { - return _realServer.isComplete(); - } - - public String getAuthorizationID() - { - return _realServer.getAuthorizationID(); - } - - public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException - { - return _realServer.unwrap(incoming, offset, len); - } - - public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException - { - return _realServer.wrap(outgoing, offset, len); - } - - public Object getNegotiatedProperty(String propName) - { - return _realServer.getNegotiatedProperty(propName); - } - - public void dispose() throws SaslException - { - _realServer.dispose(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedServerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedServerFactory.java deleted file mode 100644 index 4e82940439..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HashedServerFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.crammd5; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import javax.security.sasl.SaslServerFactory; -import java.util.Map; - -public class CRAMMD5HashedServerFactory implements SaslServerFactory -{ - public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map<String, ?> props, - CallbackHandler cbh) throws SaslException - { - if (mechanism.equals(CRAMMD5HashedSaslServer.MECHANISM)) - { - return new CRAMMD5HashedSaslServer(mechanism, protocol, serverName, props, cbh); - } - else - { - return null; - } - } - - public String[] getMechanismNames(Map props) - { - if (props != null) - { - if (props.containsKey(Sasl.POLICY_NOPLAINTEXT) || - props.containsKey(Sasl.POLICY_NODICTIONARY) || - props.containsKey(Sasl.POLICY_NOACTIVE)) - { - // returned array must be non null according to interface documentation - return new String[0]; - } - } - - return new String[]{CRAMMD5HashedSaslServer.MECHANISM}; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java deleted file mode 100644 index c4c4b4e0cf..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.crammd5; - -import java.io.File; -import java.io.IOException; -import java.security.Principal; -import java.util.List; - -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.login.AccountNotFoundException; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; -import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser; - -public class CRAMMD5HexInitialiser extends UsernamePasswordInitialiser -{ - public String getMechanismName() - { - return CRAMMD5HexSaslServer.MECHANISM; - } - - public void initialise(PrincipalDatabase db) - { - super.initialise(new HexifyPrincipalDatabase(db)); - - } - - private static class HexifyPrincipalDatabase implements PrincipalDatabase - { - private PrincipalDatabase _realPricipalDatabase; - - HexifyPrincipalDatabase(PrincipalDatabase db) - { - _realPricipalDatabase = db; - } - - private char[] toHex(char[] password) - { - StringBuilder sb = new StringBuilder(); - for (char c : password) - { - //toHexString does not prepend 0 so we have to - if (((byte) c > -1) && (byte) c < 0x10 ) - { - sb.append(0); - } - - sb.append(Integer.toHexString(c & 0xFF)); - } - - //Extract the hex string as char[] - char[] hex = new char[sb.length()]; - - sb.getChars(0, sb.length(), hex, 0); - - return hex; - } - - public void setPassword(Principal principal, PasswordCallback callback) throws IOException, AccountNotFoundException - { - //Let the read DB set the password - _realPricipalDatabase.setPassword(principal, callback); - - //Retrieve the setpassword - char[] plainPassword = callback.getPassword(); - - char[] hexPassword = toHex(plainPassword); - - callback.setPassword(hexPassword); - } - - // Simply delegate to the real PrincipalDB - public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException - { - return _realPricipalDatabase.verifyPassword(principal, password); - } - - public boolean updatePassword(Principal principal, char[] password) throws AccountNotFoundException - { - return _realPricipalDatabase.updatePassword(principal, password); - } - - public boolean createPrincipal(Principal principal, char[] password) - { - return _realPricipalDatabase.createPrincipal(principal, password); - } - - public boolean deletePrincipal(Principal principal) throws AccountNotFoundException - { - return _realPricipalDatabase.deletePrincipal(principal); - } - - public Principal getUser(String username) - { - return _realPricipalDatabase.getUser(username); - } - - public List<Principal> getUsers() - { - return _realPricipalDatabase.getUsers(); - } - - public void reload() throws IOException - { - _realPricipalDatabase.reload(); - } - - @Override - public void open(File passwordFile) throws IOException - { - throw new UnsupportedOperationException(); - } - - @Override - public String getMechanisms() - { - return _realPricipalDatabase.getMechanisms(); - } - - @Override - public SaslServer createSaslServer(String mechanism, String localFQDN, - Principal externalPrincipal) throws SaslException - { - return _realPricipalDatabase.createSaslServer(mechanism, localFQDN, externalPrincipal); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexSaslServer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexSaslServer.java deleted file mode 100644 index e19baaa7c6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexSaslServer.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.crammd5; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import javax.security.sasl.SaslServerFactory; -import java.util.Enumeration; -import java.util.Map; - -public class CRAMMD5HexSaslServer implements SaslServer -{ - public static final String MECHANISM = "CRAM-MD5-HEX"; - - private SaslServer _realServer; - - public CRAMMD5HexSaslServer(String mechanism, String protocol, String serverName, Map<String, ?> props, - CallbackHandler cbh) throws SaslException - { - Enumeration factories = Sasl.getSaslServerFactories(); - - while (factories.hasMoreElements()) - { - SaslServerFactory factory = (SaslServerFactory) factories.nextElement(); - - if (factory instanceof CRAMMD5HexServerFactory) - { - continue; - } - - String[] mechs = factory.getMechanismNames(props); - - for (String mech : mechs) - { - if (mech.equals("CRAM-MD5")) - { - _realServer = factory.createSaslServer("CRAM-MD5", protocol, serverName, props, cbh); - return; - } - } - } - - throw new RuntimeException("No default SaslServer found for mechanism:" + "CRAM-MD5"); - } - - public String getMechanismName() - { - return MECHANISM; - } - - public byte[] evaluateResponse(byte[] response) throws SaslException - { - return _realServer.evaluateResponse(response); - } - - public boolean isComplete() - { - return _realServer.isComplete(); - } - - public String getAuthorizationID() - { - return _realServer.getAuthorizationID(); - } - - public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException - { - return _realServer.unwrap(incoming, offset, len); - } - - public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException - { - return _realServer.wrap(outgoing, offset, len); - } - - public Object getNegotiatedProperty(String propName) - { - return _realServer.getNegotiatedProperty(propName); - } - - public void dispose() throws SaslException - { - _realServer.dispose(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexServerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexServerFactory.java deleted file mode 100644 index 06c9108a73..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexServerFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.crammd5; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import javax.security.sasl.SaslServerFactory; -import java.util.Map; - -public class CRAMMD5HexServerFactory implements SaslServerFactory -{ - public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map<String, ?> props, - CallbackHandler cbh) throws SaslException - { - if (mechanism.equals(CRAMMD5HexSaslServer.MECHANISM)) - { - return new CRAMMD5HexSaslServer(mechanism, protocol, serverName, props, cbh); - } - else - { - return null; - } - } - - public String[] getMechanismNames(Map props) - { - if (props != null) - { - if (props.containsKey(Sasl.POLICY_NOPLAINTEXT) || - props.containsKey(Sasl.POLICY_NODICTIONARY) || - props.containsKey(Sasl.POLICY_NOACTIVE)) - { - // returned array must be non null according to interface documentation - return new String[0]; - } - } - - return new String[]{CRAMMD5HexSaslServer.MECHANISM}; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5Initialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5Initialiser.java deleted file mode 100644 index 70c13233b0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5Initialiser.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.crammd5; - -import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser; - -public class CRAMMD5Initialiser extends UsernamePasswordInitialiser -{ - public static final String MECHANISM = "CRAM-MD5"; - - public String getMechanismName() - { - return MECHANISM; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/external/ExternalSaslServer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/external/ExternalSaslServer.java deleted file mode 100644 index e1007d91e0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/external/ExternalSaslServer.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.external; - -import java.security.Principal; - -import javax.security.auth.x500.X500Principal; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import org.apache.log4j.Logger; -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.transport.network.security.ssl.SSLUtil; - -public class ExternalSaslServer implements SaslServer -{ - private static final Logger LOGGER = Logger.getLogger(ExternalSaslServer.class); - - public static final String MECHANISM = "EXTERNAL"; - - private boolean _complete = false; - private final Principal _externalPrincipal; - private boolean _useFullDN = false; - - public ExternalSaslServer(Principal externalPrincipal, boolean useFullDN) - { - _useFullDN = useFullDN; - _externalPrincipal = externalPrincipal; - } - - public String getMechanismName() - { - return MECHANISM; - } - - public byte[] evaluateResponse(byte[] response) throws SaslException - { - _complete = true; - return null; - } - - public boolean isComplete() - { - return _complete; - } - - public String getAuthorizationID() - { - return getAuthenticatedPrincipal().getName(); - } - - public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException - { - throw new SaslException("Unsupported operation"); - } - - public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException - { - throw new SaslException("Unsupported operation"); - } - - public Object getNegotiatedProperty(String propName) - { - return null; - } - - public void dispose() throws SaslException - { - } - - public Principal getAuthenticatedPrincipal() - { - if (_externalPrincipal instanceof X500Principal && !_useFullDN) - { - // Construct username as <CN>@<DC1>.<DC2>.<DC3>....<DCN> - String username; - String dn = ((X500Principal) _externalPrincipal).getName(X500Principal.RFC2253); - - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("Parsing username from Principal DN: " + dn); - } - - username = SSLUtil.getIdFromSubjectDN(dn); - if (username.isEmpty()) - { - // CN is empty => Cannot construct username => Authentication failed => return null - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("CN value was empty in Principal name, unable to construct username"); - } - return null; - } - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("Constructing Principal with username: " + username); - } - return new UsernamePrincipal(username); - } - else - { - if(LOGGER.isDebugEnabled()) - { - LOGGER.debug("Using external Principal: " + _externalPrincipal); - } - return _externalPrincipal; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainInitialiser.java deleted file mode 100644 index 05acd3b27f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainInitialiser.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.plain; - -import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser; - -public class PlainInitialiser extends UsernamePasswordInitialiser -{ - public String getMechanismName() - { - return "PLAIN"; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainPasswordCallback.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainPasswordCallback.java deleted file mode 100644 index 0ea2f3c92e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainPasswordCallback.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.plain; - -import javax.security.auth.callback.PasswordCallback; -import java.util.Arrays; - -/** - * Custom PasswordCallback for use during the PLAIN authentication process. - * - * To be used in combination with PrincipalDatabase implementations that - * can either set a plain text value in the parent callback, or use the - * setAuthenticated(bool) method after observing the incoming plain text. - * - * isAuthenticated() should then be used to determine the final result. - * - */ -public class PlainPasswordCallback extends PasswordCallback -{ - private char[] _plainPassword; - private boolean _authenticated = false; - - /** - * Constructs a new PlainPasswordCallback with the incoming plain text password. - * - * @throws NullPointerException if the incoming plain text is null - */ - public PlainPasswordCallback(String prompt, boolean echoOn, String plainPassword) - { - super(prompt, echoOn); - - if(plainPassword == null) - { - throw new NullPointerException("Incoming plain text cannot be null"); - } - - _plainPassword = plainPassword.toCharArray(); - } - - public String getPlainPassword() - { - return new String(_plainPassword); - } - - public void setAuthenticated(boolean authenticated) - { - _authenticated = authenticated; - } - - /** - * Method to determine if the incoming plain password is authenticated - * - * @return true if the stored password matches the incoming text, or setAuthenticated(true) has been called - */ - public boolean isAuthenticated() - { - char[] storedPassword = getPassword(); - - return Arrays.equals(_plainPassword, storedPassword) || _authenticated; - } -} - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainSaslServer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainSaslServer.java deleted file mode 100644 index a811806c00..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainSaslServer.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.plain; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.sasl.AuthorizeCallback; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import java.io.IOException; - -public class PlainSaslServer implements SaslServer -{ - public static final String MECHANISM = "PLAIN"; - - private CallbackHandler _cbh; - - private String _authorizationId; - - private boolean _complete = false; - - public PlainSaslServer(CallbackHandler cbh) - { - _cbh = cbh; - } - - public String getMechanismName() - { - return MECHANISM; - } - - public byte[] evaluateResponse(byte[] response) throws SaslException - { - int authzidNullPosition = findNullPosition(response, 0); - if (authzidNullPosition < 0) - { - throw new SaslException("Invalid PLAIN encoding, authzid null terminator not found"); - } - int authcidNullPosition = findNullPosition(response, authzidNullPosition + 1); - if (authcidNullPosition < 0) - { - throw new SaslException("Invalid PLAIN encoding, authcid null terminator not found"); - } - - PlainPasswordCallback passwordCb; - AuthorizeCallback authzCb; - - try - { - // we do not currently support authcid in any meaningful way - String authzid = new String(response, authzidNullPosition + 1, authcidNullPosition - authzidNullPosition - 1, "utf8"); - - // TODO: should not get pwd as a String but as a char array... - int passwordLen = response.length - authcidNullPosition - 1; - String pwd = new String(response, authcidNullPosition + 1, passwordLen, "utf8"); - - // we do not care about the prompt but it throws if null - NameCallback nameCb = new NameCallback("prompt", authzid); - passwordCb = new PlainPasswordCallback("prompt", false, pwd); - authzCb = new AuthorizeCallback(authzid, authzid); - - Callback[] callbacks = new Callback[]{nameCb, passwordCb, authzCb}; - _cbh.handle(callbacks); - - } - catch (IOException e) - { - if(e instanceof SaslException) - { - throw (SaslException) e; - } - throw new SaslException("Error processing data: " + e, e); - } - catch (UnsupportedCallbackException e) - { - throw new SaslException("Unable to obtain data from callback handler: " + e, e); - } - - if (passwordCb.isAuthenticated()) - { - _complete = true; - } - - if (authzCb.isAuthorized() && _complete) - { - _authorizationId = authzCb.getAuthenticationID(); - return null; - } - else - { - throw new SaslException("Authentication failed"); - } - } - - - - private int findNullPosition(byte[] response, int startPosition) - { - int position = startPosition; - while (position < response.length) - { - if (response[position] == (byte) 0) - { - return position; - } - position++; - } - return -1; - } - - public boolean isComplete() - { - return _complete; - } - - public String getAuthorizationID() - { - return _authorizationId; - } - - public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException - { - throw new SaslException("Unsupported operation"); - } - - public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException - { - throw new SaslException("Unsupported operation"); - } - - public Object getNegotiatedProperty(String propName) - { - return null; - } - - public void dispose() throws SaslException - { - _cbh = null; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainSaslServerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainSaslServerFactory.java deleted file mode 100644 index 445e5ef812..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/plain/PlainSaslServerFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.auth.sasl.plain; - -import javax.security.auth.callback.CallbackHandler; -import javax.security.sasl.Sasl; -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import javax.security.sasl.SaslServerFactory; -import java.util.Map; - -public class PlainSaslServerFactory implements SaslServerFactory -{ - public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map props, - CallbackHandler cbh) throws SaslException - { - if (PlainSaslServer.MECHANISM.equals(mechanism)) - { - return new PlainSaslServer(cbh); - } - else - { - return null; - } - } - - public String[] getMechanismNames(Map props) - { - if (props != null && - (props.containsKey(Sasl.POLICY_NOPLAINTEXT) || - props.containsKey(Sasl.POLICY_NODICTIONARY) || - props.containsKey(Sasl.POLICY_NOACTIVE))) - { - // returned array must be non null according to interface documentation - return new String[0]; - } - else - { - return new String[]{PlainSaslServer.MECHANISM}; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java deleted file mode 100644 index c66e7fd4e4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.group; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Collections; -import java.util.Date; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentSkipListSet; - -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; - -/** - * A group database that reads/writes the following file format: - * - * group1.users=user1,user2 - * group2.users=user2,user3 - */ -public class FileGroupDatabase implements GroupDatabase -{ - private static final Logger LOGGER = Logger.getLogger(FileGroupDatabase.class); - - private Map<String, Set<String>> _groupToUserMap = new ConcurrentHashMap<String, Set<String>>(); - private Map<String, Set<String>> _userToGroupMap = new ConcurrentHashMap<String, Set<String>>(); - private String _groupFile; - - @Override - public Set<String> getAllGroups() - { - return Collections.unmodifiableSet(_groupToUserMap.keySet()); - } - - public synchronized void setGroupFile(String groupFile) throws IOException - { - File file = new File(groupFile); - - if (!file.canRead()) - { - throw new FileNotFoundException(groupFile - + " cannot be found or is not readable"); - } - - readGroupFile(groupFile); - } - - @Override - public Set<String> getUsersInGroup(String group) - { - if (group == null) - { - LOGGER.warn("Requested user set for null group. Returning empty set."); - return Collections.emptySet(); - } - - Set<String> set = _groupToUserMap.get(group); - if (set == null) - { - return Collections.emptySet(); - } - else - { - return Collections.unmodifiableSet(set); - } - } - - @Override - public synchronized void addUserToGroup(String user, String group) - { - Set<String> users = _groupToUserMap.get(group); - if (users == null) - { - throw new IllegalArgumentException("Group " + group + " does not exist so could not add " + user + " to it"); - } - - users.add(user); - - Set<String> groups = _userToGroupMap.get(user); - if (groups == null) - { - groups = new ConcurrentSkipListSet<String>(); - _userToGroupMap.put(user, groups); - } - groups.add(group); - - update(); - } - - @Override - public synchronized void removeUserFromGroup(String user, String group) - { - Set<String> users = _groupToUserMap.get(group); - if (users == null) - { - throw new IllegalArgumentException("Group " + group + " does not exist so could not remove " + user + " from it"); - } - - users.remove(user); - - Set<String> groups = _userToGroupMap.get(user); - if (groups != null) - { - groups.remove(group); - } - - update(); - } - - @Override - public Set<String> getGroupsForUser(String user) - { - if(user == null) - { - LOGGER.warn("Requested group set for null user. Returning empty set."); - return Collections.emptySet(); - } - - Set<String> groups = _userToGroupMap.get(user); - if (groups == null) - { - return Collections.emptySet(); - } - else - { - return Collections.unmodifiableSet(groups); - } - } - - @Override - public synchronized void createGroup(String group) - { - Set<String> users = new ConcurrentSkipListSet<String>(); - _groupToUserMap.put(group, users); - - update(); - } - - @Override - public synchronized void removeGroup(String group) - { - _groupToUserMap.remove(group); - for (Set<String> groupsForUser : _userToGroupMap.values()) - { - groupsForUser.remove(group); - } - - update(); - } - - private synchronized void update() - { - if (_groupFile != null) - { - try - { - writeGroupFile(_groupFile); - } - catch (IOException e) - { - throw new RuntimeException("Unable to persist change to file " + _groupFile); - } - } - } - - private synchronized void readGroupFile(String groupFile) throws IOException - { - _groupFile = groupFile; - _groupToUserMap.clear(); - _userToGroupMap.clear(); - Properties propertiesFile = new Properties(); - FileInputStream fileInputStream = new FileInputStream(groupFile); - try - { - propertiesFile.load(fileInputStream); - } - finally - { - if(fileInputStream != null) - { - fileInputStream.close(); - } - } - - for (String propertyName : propertiesFile.stringPropertyNames()) - { - validatePropertyNameIsGroupName(propertyName); - - String groupName = propertyName.replaceAll("\\.users$", ""); - String userString = propertiesFile.getProperty(propertyName); - - final Set<String> userSet = buildUserSetFromCommaSeparateValue(userString); - - _groupToUserMap.put(groupName, userSet); - - for (String userName : userSet) - { - Set<String> groupsForThisUser = _userToGroupMap.get(userName); - - if (groupsForThisUser == null) - { - groupsForThisUser = new ConcurrentSkipListSet<String>(); - _userToGroupMap.put(userName, groupsForThisUser); - } - - groupsForThisUser.add(groupName); - } - } - } - - private synchronized void writeGroupFile(String groupFile) throws IOException - { - Properties propertiesFile = new Properties(); - - for (String group : _groupToUserMap.keySet()) - { - Set<String> users = _groupToUserMap.get(group); - String userList = StringUtils.join(users, ","); - - propertiesFile.setProperty(group + ".users", userList); - } - - String comment = "Written " + new Date(); - FileOutputStream fileOutputStream = new FileOutputStream(groupFile); - try - { - propertiesFile.store(fileOutputStream, comment); - } - finally - { - if(fileOutputStream != null) - { - fileOutputStream.close(); - } - } - } - - private void validatePropertyNameIsGroupName(String propertyName) - { - if (!propertyName.endsWith(".users")) - { - throw new IllegalArgumentException( - "Invalid definition with name '" - + propertyName - + "'. Group definitions must end with suffix '.users'"); - } - } - - private ConcurrentSkipListSet<String> buildUserSetFromCommaSeparateValue(String userString) - { - String[] users = userString.split(","); - final ConcurrentSkipListSet<String> userSet = new ConcurrentSkipListSet<String>(); - for (String user : users) - { - final String trimmed = user.trim(); - if (!trimmed.isEmpty()) - { - userSet.add(trimmed); - } - } - return userSet; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java deleted file mode 100644 index e11a4f83db..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.group; - -import java.io.File; -import java.io.IOException; -import java.security.Principal; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.security.auth.UsernamePrincipal; - -/** - * Implementation of a group manager whose implementation is backed by a flat group file. - * <p> - * This plugin is configured in the following manner: - * </p> - * <pre> - * "groupproviders":[ - * ... - * { - * "name" : "...", - * "type" : "GroupFile", - * "path" : "path/to/file/with/groups", - * } - * ... - * ] - * </pre> - */ -public class FileGroupManager implements GroupManager -{ - private final FileGroupDatabase _groupDatabase; - private final String _groupFile; - - public FileGroupManager(String groupFile) - { - _groupFile = groupFile; - _groupDatabase = new FileGroupDatabase(); - } - - @Override - public Set<Principal> getGroupPrincipalsForUser(String userId) - { - Set<String> groups = _groupDatabase.getGroupsForUser(userId); - if (groups.isEmpty()) - { - return Collections.emptySet(); - } - else - { - Set<Principal> principals = new HashSet<Principal>(); - for (String groupName : groups) - { - principals.add(new GroupPrincipal(groupName)); - } - return principals; - } - } - - @Override - public Set<Principal> getUserPrincipalsForGroup(String group) - { - Set<String> users = _groupDatabase.getUsersInGroup(group); - if (users.isEmpty()) - { - return Collections.emptySet(); - } - else - { - Set<Principal> principals = new HashSet<Principal>(); - for (String user : users) - { - principals.add(new UsernamePrincipal(user)); - } - return principals; - } - } - - @Override - public Set<Principal> getGroupPrincipals() - { - Set<String> groups = _groupDatabase.getAllGroups(); - if (groups.isEmpty()) - { - return Collections.emptySet(); - } - else - { - Set<Principal> principals = new HashSet<Principal>(); - for (String groupName : groups) - { - principals.add(new GroupPrincipal(groupName)); - } - return principals; - } - } - - @Override - public void createGroup(String group) - { - _groupDatabase.createGroup(group); - } - - @Override - public void removeGroup(String group) - { - _groupDatabase.removeGroup(group); - } - - @Override - public void addUserToGroup(String user, String group) - { - _groupDatabase.addUserToGroup(user, group); - } - - @Override - public void removeUserFromGroup(String user, String group) - { - _groupDatabase.removeUserFromGroup(user, group); - - } - - @Override - public void onDelete() - { - File file = new File(_groupFile); - if (file.exists()) - { - if (!file.delete()) - { - throw new IllegalConfigurationException("Cannot delete group file"); - } - } - } - - @Override - public void onCreate() - { - File file = new File(_groupFile); - if (!file.exists()) - { - File parent = file.getParentFile(); - if (!parent.exists()) - { - parent.mkdirs(); - } - if (parent.exists()) - { - try - { - file.createNewFile(); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Cannot create group file"); - } - } - else - { - throw new IllegalConfigurationException("Cannot create group file"); - } - } - } - - @Override - public void open() - { - try - { - _groupDatabase.setGroupFile(_groupFile); - } - catch (IOException e) - { - throw new IllegalConfigurationException("Unable to set group file " + _groupFile, e); - } - } - - @Override - public void close() - { - // no-op - } - - @Override - public int hashCode() - { - return ((_groupFile == null) ? 0 : _groupFile.hashCode()); - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - FileGroupManager other = (FileGroupManager) obj; - if (_groupFile == null) - { - if (other._groupFile != null) - { - return false; - } - else - { - return true; - } - } - return _groupFile.equals(other._groupFile); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java deleted file mode 100644 index 50f08623cd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.group; - -import static org.apache.qpid.server.util.MapValueConverter.getStringAttribute; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.plugin.GroupManagerFactory; -import org.apache.qpid.server.util.ResourceBundleLoader; - -public class FileGroupManagerFactory implements GroupManagerFactory -{ - public static final String RESOURCE_BUNDLE = "org.apache.qpid.server.security.group.FileGroupProviderAttributeDescriptions"; - - public static final String GROUP_FILE_PROVIDER_TYPE = "GroupFile"; - public static final String PATH = "path"; - - public static final Collection<String> ATTRIBUTES = Collections.<String> unmodifiableList(Arrays.asList( - ATTRIBUTE_TYPE, - PATH - )); - - @Override - public GroupManager createInstance(Map<String, Object> attributes) - { - if(attributes == null || !GROUP_FILE_PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE))) - { - return null; - } - - String groupFile = getStringAttribute(PATH, attributes, null); - if (groupFile == null || "".equals(groupFile.trim())) - { - throw new IllegalConfigurationException("Path to file containing groups is not specified!"); - } - - return new FileGroupManager(groupFile); - } - - @Override - public String getType() - { - return GROUP_FILE_PROVIDER_TYPE; - } - - @Override - public Collection<String> getAttributeNames() - { - return ATTRIBUTES; - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return ResourceBundleLoader.getResources(RESOURCE_BUNDLE); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupProviderAttributeDescriptions.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupProviderAttributeDescriptions.properties deleted file mode 100644 index 2c2d2ab9e3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupProviderAttributeDescriptions.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. - -path= File location* diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupDatabase.java deleted file mode 100644 index 98c12782d8..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupDatabase.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.group; - -import java.util.Set; - -public interface GroupDatabase -{ - Set<String> getAllGroups(); - Set<String> getUsersInGroup(String group); - - void addUserToGroup(String user, String group); - void removeUserFromGroup(String user, String group); - Set<String> getGroupsForUser(String user); - void createGroup(String group); - void removeGroup(String group); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java deleted file mode 100644 index 3fd6dd2800..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.group; - -import java.security.Principal; -import java.util.Set; - -public interface GroupManager -{ - Set<Principal> getGroupPrincipalsForUser(String user); - - Set<Principal> getGroupPrincipals(); - - Set<Principal> getUserPrincipalsForGroup(String group); - - void createGroup(String group); - - void removeGroup(String group); - - void addUserToGroup(String user, String group); - - void removeUserFromGroup(String user, String group); - - void open(); - - void close(); - - void onDelete(); - - void onCreate(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipal.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipal.java deleted file mode 100644 index a9590bb964..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipal.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.security.group; - -import java.io.Serializable; -import java.security.Principal; -import java.security.acl.Group; -import java.util.Enumeration; - -/** - * Immutable representation of a user group. In Qpid, groups do <b>not</b> know - * about their membership, and therefore the {@link #addMember(Principal)} - * methods etc throw {@link UnsupportedOperationException}. - * - */ -public class GroupPrincipal implements Group, Serializable -{ - /** Name of the group */ - private final String _groupName; - - public GroupPrincipal(final String groupName) - { - _groupName = groupName; - } - - public String getName() - { - return _groupName; - } - - public boolean addMember(Principal user) - { - throw new UnsupportedOperationException("Not supported"); - } - - public boolean removeMember(Principal user) - { - throw new UnsupportedOperationException("Not supported"); - } - - public boolean isMember(Principal member) - { - throw new UnsupportedOperationException("Not supported"); - } - - public Enumeration<? extends Principal> members() - { - throw new UnsupportedOperationException("Not supported"); - } - - /** - * @see java.lang.Object#hashCode() - */ - public int hashCode() - { - final int prime = 37; - return prime * _groupName.hashCode(); - } - - /** - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - else - { - if (obj instanceof GroupPrincipal) - { - GroupPrincipal other = (GroupPrincipal) obj; - return _groupName.equals(other._groupName); - } - else - { - return false; - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java deleted file mode 100644 index f382f90010..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsCounter.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.stats; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; -import java.util.concurrent.atomic.AtomicLong; - -/** - * This class collects statistics and counts the total, rate per second and - * peak rate per second values for the events that are registered with it. - */ -public class StatisticsCounter -{ - private static final Logger _log = LoggerFactory.getLogger(StatisticsCounter.class); - - public static final long DEFAULT_SAMPLE_PERIOD = Long.getLong("qpid.statistics.samplePeriod", 2000L); // 2s - - private static final String COUNTER = "counter"; - private static final AtomicLong _counterIds = new AtomicLong(0L); - - private long _peak = 0L; - private long _total = 0L; - private long _temp = 0L; - private long _last = 0L; - private long _rate = 0L; - - private long _start; - - private final long _period; - private final String _name; - - public StatisticsCounter() - { - this(COUNTER); - } - - public StatisticsCounter(String name) - { - this(name, DEFAULT_SAMPLE_PERIOD); - } - - public StatisticsCounter(String name, long period) - { - _period = period; - _name = name + "-" + + _counterIds.incrementAndGet(); - reset(); - } - - public void registerEvent() - { - registerEvent(1L); - } - - public void registerEvent(long value) - { - registerEvent(value, System.currentTimeMillis()); - } - - public void registerEvent(long value, long timestamp) - { - long thisSample = (timestamp / _period); - synchronized (this) - { - if (thisSample > _last) - { - _last = thisSample; - _rate = _temp; - _temp = 0L; - if (_rate > _peak) - { - _peak = _rate; - } - } - - _total += value; - _temp += value; - } - } - - /** - * Update the current rate and peak - may reset rate to zero if a new - * sample period has started. - */ - private void update() - { - registerEvent(0L, System.currentTimeMillis()); - } - - /** - * Reset - */ - public void reset() - { - _log.info("Resetting statistics for counter: " + _name); - _peak = 0L; - _rate = 0L; - _total = 0L; - _start = System.currentTimeMillis(); - _last = _start / _period; - } - - public double getPeak() - { - update(); - return (double) _peak / ((double) _period / 1000.0d); - } - - public double getRate() - { - update(); - return (double) _rate / ((double) _period / 1000.0d); - } - - public long getTotal() - { - return _total; - } - - public long getStart() - { - return _start; - } - - public Date getStartTime() - { - return new Date(_start); - } - - public String getName() - { - return _name; - } - - public long getPeriod() - { - return _period; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsGatherer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsGatherer.java deleted file mode 100644 index 37d87bb628..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/stats/StatisticsGatherer.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.stats; - -/** - * This interface is to be implemented by any broker business object that - * wishes to gather statistics about messages delivered through it. - * - * These statistics are exposed using a separate JMX Mbean interface, which - * calls these methods to retrieve the underlying {@link StatisticsCounter}s - * and return their attributes. This interface gives a standard way for - * parts of the broker to set up and configure statistics generation. - * <p> - * When creating these objects, there should be a parent/child relationship - * between them, such that the lowest level gatherer can record staticics if - * enabled, and pass on the notification to the parent object to allow higher - * level aggregation. When resetting statistics, this works in the opposite - * direction, with higher level gatherers also resetting all of their children. - */ -public interface StatisticsGatherer -{ - /** - * Initialise the statistics gathering for this object. - * - * This method is responsible for creating any {@link StatisticsCounter} - * objects and for determining whether statistics generation should be - * enabled, by checking broker and system configuration. - * - * @see StatisticsCounter#DISABLE_STATISTICS - */ - void initialiseStatistics(); - - /** - * This method is responsible for registering the receipt of a message - * with the counters, and also for passing this notification to any parent - * {@link StatisticsGatherer}s. If statistics generation is not enabled, - * then this method should simple delegate to the parent gatherer. - * - * @param messageSize the size in bytes of the delivered message - * @param timestamp the time the message was delivered - */ - void registerMessageReceived(long messageSize, long timestamp); - - /** - * This method is responsible for registering the delivery of a message - * with the counters. Message delivery is recorded by the counter using - * the current system time, as opposed to the message timestamp. - * - * @param messageSize the size in bytes of the delivered message - * @see #registerMessageReceived(long, long) - */ - void registerMessageDelivered(long messageSize); - - /** - * Gives access to the {@link StatisticsCounter} that is used to count - * delivered message statistics. - * - * @return the {@link StatisticsCounter} that counts delivered messages - */ - StatisticsCounter getMessageDeliveryStatistics(); - - /** - * Gives access to the {@link StatisticsCounter} that is used to count - * received message statistics. - * - * @return the {@link StatisticsCounter} that counts received messages - */ - StatisticsCounter getMessageReceiptStatistics(); - - /** - * Gives access to the {@link StatisticsCounter} that is used to count - * delivered message size statistics. - * - * @return the {@link StatisticsCounter} that counts delivered bytes - */ - StatisticsCounter getDataDeliveryStatistics(); - - /** - * Gives access to the {@link StatisticsCounter} that is used to count - * received message size statistics. - * - * @return the {@link StatisticsCounter} that counts received bytes - */ - StatisticsCounter getDataReceiptStatistics(); - - /** - * Reset the counters for this, and any child {@link StatisticsGatherer}s. - */ - void resetStatistics(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractDurableConfiguredObjectRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractDurableConfiguredObjectRecoverer.java deleted file mode 100644 index dbe8bf22a0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractDurableConfiguredObjectRecoverer.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Map; -import java.util.UUID; - -public abstract class AbstractDurableConfiguredObjectRecoverer<T> implements DurableConfiguredObjectRecoverer -{ - @Override - public void load(final DurableConfigurationRecoverer durableConfigurationRecoverer, - final UUID id, - final Map<String, Object> attributes) - { - final UnresolvedObject obj = createUnresolvedObject(id, getType(), attributes); - UnresolvedDependency[] dependencies = obj.getUnresolvedDependencies(); - for(final UnresolvedDependency dependency : dependencies) - { - Object dep; - if((dep = durableConfigurationRecoverer.getResolvedObject(dependency.getType(), dependency.getId())) != null) - { - dependency.resolve(dep); - } - else - { - durableConfigurationRecoverer.addResolutionListener(dependency.getType(), dependency.getId(), - new DependencyListener() - { - - @Override - public void dependencyResolved(final String depType, - final UUID depId, - final Object o) - { - dependency.resolve(o); - if(obj.getUnresolvedDependencies().length == 0) - { - durableConfigurationRecoverer.resolve(getType(), id, obj.resolve()); - } - } - }); - } - } - if(obj.getUnresolvedDependencies().length == 0) - { - durableConfigurationRecoverer.resolve(getType(), id, obj.resolve()); - } - else - { - durableConfigurationRecoverer.addUnresolvedObject(getType(), id, obj); - } - - } - - public abstract UnresolvedObject<T> createUnresolvedObject(final UUID id, - final String type, - final Map<String, Object> attributes); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractJDBCMessageStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractJDBCMessageStore.java deleted file mode 100644 index 4a1452d86c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractJDBCMessageStore.java +++ /dev/null @@ -1,2363 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.store; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.lang.ref.SoftReference; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Types; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.plugin.MessageMetaDataType; -import org.apache.qpid.server.queue.AMQQueue; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; - -abstract public class AbstractJDBCMessageStore implements MessageStore, DurableConfigurationStore -{ - private static final String DB_VERSION_TABLE_NAME = "QPID_DB_VERSION"; - private static final String CONFIGURATION_VERSION_TABLE_NAME = "QPID_CONFIG_VERSION"; - - private static final String QUEUE_ENTRY_TABLE_NAME = "QPID_QUEUE_ENTRIES"; - - private static final String META_DATA_TABLE_NAME = "QPID_MESSAGE_METADATA"; - private static final String MESSAGE_CONTENT_TABLE_NAME = "QPID_MESSAGE_CONTENT"; - - private static final String LINKS_TABLE_NAME = "QPID_LINKS"; - private static final String BRIDGES_TABLE_NAME = "QPID_BRIDGES"; - - private static final String XID_TABLE_NAME = "QPID_XIDS"; - private static final String XID_ACTIONS_TABLE_NAME = "QPID_XID_ACTIONS"; - - private static final String CONFIGURED_OBJECTS_TABLE_NAME = "QPID_CONFIGURED_OBJECTS"; - private static final int DEFAULT_CONFIG_VERSION = 0; - - public static String[] ALL_TABLES = new String[] { DB_VERSION_TABLE_NAME, LINKS_TABLE_NAME, BRIDGES_TABLE_NAME, XID_ACTIONS_TABLE_NAME, - XID_TABLE_NAME, QUEUE_ENTRY_TABLE_NAME, MESSAGE_CONTENT_TABLE_NAME, META_DATA_TABLE_NAME, CONFIGURED_OBJECTS_TABLE_NAME, CONFIGURATION_VERSION_TABLE_NAME }; - - private static final int DB_VERSION = 7; - - private final AtomicLong _messageId = new AtomicLong(0); - private AtomicBoolean _closed = new AtomicBoolean(false); - - private static final String CREATE_DB_VERSION_TABLE = "CREATE TABLE "+ DB_VERSION_TABLE_NAME + " ( version int not null )"; - private static final String INSERT_INTO_DB_VERSION = "INSERT INTO "+ DB_VERSION_TABLE_NAME + " ( version ) VALUES ( ? )"; - private static final String SELECT_FROM_DB_VERSION = "SELECT version FROM " + DB_VERSION_TABLE_NAME; - private static final String UPDATE_DB_VERSION = "UPDATE " + DB_VERSION_TABLE_NAME + " SET version = ?"; - - - private static final String CREATE_CONFIG_VERSION_TABLE = "CREATE TABLE "+ CONFIGURATION_VERSION_TABLE_NAME + " ( version int not null )"; - private static final String INSERT_INTO_CONFIG_VERSION = "INSERT INTO "+ CONFIGURATION_VERSION_TABLE_NAME + " ( version ) VALUES ( ? )"; - private static final String SELECT_FROM_CONFIG_VERSION = "SELECT version FROM " + CONFIGURATION_VERSION_TABLE_NAME; - private static final String UPDATE_CONFIG_VERSION = "UPDATE " + CONFIGURATION_VERSION_TABLE_NAME + " SET version = ?"; - - - private static final String INSERT_INTO_QUEUE_ENTRY = "INSERT INTO " + QUEUE_ENTRY_TABLE_NAME + " (queue_id, message_id) values (?,?)"; - private static final String DELETE_FROM_QUEUE_ENTRY = "DELETE FROM " + QUEUE_ENTRY_TABLE_NAME + " WHERE queue_id = ? AND message_id =?"; - private static final String SELECT_FROM_QUEUE_ENTRY = "SELECT queue_id, message_id FROM " + QUEUE_ENTRY_TABLE_NAME + " ORDER BY queue_id, message_id"; - private static final String INSERT_INTO_MESSAGE_CONTENT = "INSERT INTO " + MESSAGE_CONTENT_TABLE_NAME - + "( message_id, content ) values (?, ?)"; - private static final String SELECT_FROM_MESSAGE_CONTENT = "SELECT content FROM " + MESSAGE_CONTENT_TABLE_NAME - + " WHERE message_id = ?"; - private static final String DELETE_FROM_MESSAGE_CONTENT = "DELETE FROM " + MESSAGE_CONTENT_TABLE_NAME - + " WHERE message_id = ?"; - - private static final String INSERT_INTO_META_DATA = "INSERT INTO " + META_DATA_TABLE_NAME + "( message_id , meta_data ) values (?, ?)"; - private static final String SELECT_FROM_META_DATA = - "SELECT meta_data FROM " + META_DATA_TABLE_NAME + " WHERE message_id = ?"; - private static final String DELETE_FROM_META_DATA = "DELETE FROM " + META_DATA_TABLE_NAME + " WHERE message_id = ?"; - private static final String SELECT_ALL_FROM_META_DATA = "SELECT message_id, meta_data FROM " + META_DATA_TABLE_NAME; - - private static final String SELECT_FROM_LINKS = - "SELECT create_time, arguments FROM " + LINKS_TABLE_NAME + " WHERE id_lsb = ? and id_msb"; - private static final String DELETE_FROM_LINKS = "DELETE FROM " + LINKS_TABLE_NAME - + " WHERE id_lsb = ? and id_msb = ?"; - private static final String SELECT_ALL_FROM_LINKS = "SELECT id_lsb, id_msb, create_time, " - + "arguments FROM " + LINKS_TABLE_NAME; - private static final String FIND_LINK = "SELECT id_lsb, id_msb FROM " + LINKS_TABLE_NAME + " WHERE id_lsb = ? and" - + " id_msb = ?"; - private static final String INSERT_INTO_LINKS = "INSERT INTO " + LINKS_TABLE_NAME + "( id_lsb, " - + "id_msb, create_time, arguments ) values (?, ?, ?, ?)"; - private static final String SELECT_FROM_BRIDGES = - "SELECT create_time, link_id_lsb, link_id_msb, arguments FROM " - + BRIDGES_TABLE_NAME + " WHERE id_lsb = ? and id_msb = ?"; - private static final String DELETE_FROM_BRIDGES = "DELETE FROM " + BRIDGES_TABLE_NAME - + " WHERE id_lsb = ? and id_msb = ?"; - private static final String SELECT_ALL_FROM_BRIDGES = "SELECT id_lsb, id_msb, " - + " create_time," - + " link_id_lsb, link_id_msb, " - + "arguments FROM " + BRIDGES_TABLE_NAME - + " WHERE link_id_lsb = ? and link_id_msb = ?"; - private static final String FIND_BRIDGE = "SELECT id_lsb, id_msb FROM " + BRIDGES_TABLE_NAME + - " WHERE id_lsb = ? and id_msb = ?"; - private static final String INSERT_INTO_BRIDGES = "INSERT INTO " + BRIDGES_TABLE_NAME + "( id_lsb, id_msb, " - + "create_time, " - + "link_id_lsb, link_id_msb, " - + "arguments )" - + " values (?, ?, ?, ?, ?, ?)"; - - private static final String INSERT_INTO_XIDS = - "INSERT INTO "+ XID_TABLE_NAME +" ( format, global_id, branch_id ) values (?, ?, ?)"; - private static final String DELETE_FROM_XIDS = "DELETE FROM " + XID_TABLE_NAME - + " WHERE format = ? and global_id = ? and branch_id = ?"; - private static final String SELECT_ALL_FROM_XIDS = "SELECT format, global_id, branch_id FROM " + XID_TABLE_NAME; - private static final String INSERT_INTO_XID_ACTIONS = - "INSERT INTO "+ XID_ACTIONS_TABLE_NAME +" ( format, global_id, branch_id, action_type, " + - "queue_id, message_id ) values (?,?,?,?,?,?) "; - private static final String DELETE_FROM_XID_ACTIONS = "DELETE FROM " + XID_ACTIONS_TABLE_NAME - + " WHERE format = ? and global_id = ? and branch_id = ?"; - private static final String SELECT_ALL_FROM_XID_ACTIONS = - "SELECT action_type, queue_id, message_id FROM " + XID_ACTIONS_TABLE_NAME + - " WHERE format = ? and global_id = ? and branch_id = ?"; - private static final String INSERT_INTO_CONFIGURED_OBJECTS = "INSERT INTO " + CONFIGURED_OBJECTS_TABLE_NAME - + " ( id, object_type, attributes) VALUES (?,?,?)"; - private static final String UPDATE_CONFIGURED_OBJECTS = "UPDATE " + CONFIGURED_OBJECTS_TABLE_NAME - + " set object_type =?, attributes = ? where id = ?"; - private static final String DELETE_FROM_CONFIGURED_OBJECTS = "DELETE FROM " + CONFIGURED_OBJECTS_TABLE_NAME - + " where id = ?"; - private static final String FIND_CONFIGURED_OBJECT = "SELECT object_type, attributes FROM " + CONFIGURED_OBJECTS_TABLE_NAME - + " where id = ?"; - private static final String SELECT_FROM_CONFIGURED_OBJECTS = "SELECT id, object_type, attributes FROM " + CONFIGURED_OBJECTS_TABLE_NAME; - - protected static final Charset UTF8_CHARSET = Charset.forName("UTF-8"); - - protected final EventManager _eventManager = new EventManager(); - - protected final StateManager _stateManager; - - private MessageStoreRecoveryHandler _messageRecoveryHandler; - private TransactionLogRecoveryHandler _tlogRecoveryHandler; - private ConfigurationRecoveryHandler _configRecoveryHandler; - private VirtualHost _virtualHost; - - public AbstractJDBCMessageStore() - { - _stateManager = new StateManager(_eventManager); - } - - @Override - public void configureConfigStore(VirtualHost virtualHost, ConfigurationRecoveryHandler configRecoveryHandler) throws Exception - { - _stateManager.attainState(State.INITIALISING); - _configRecoveryHandler = configRecoveryHandler; - _virtualHost = virtualHost; - - } - - @Override - public void configureMessageStore(VirtualHost virtualHost, MessageStoreRecoveryHandler recoveryHandler, - TransactionLogRecoveryHandler tlogRecoveryHandler) throws Exception - { - if(_stateManager.isInState(State.INITIAL)) - { - _stateManager.attainState(State.INITIALISING); - } - - _virtualHost = virtualHost; - _tlogRecoveryHandler = tlogRecoveryHandler; - _messageRecoveryHandler = recoveryHandler; - - completeInitialisation(); - } - - private void completeInitialisation() throws ClassNotFoundException, SQLException, AMQStoreException - { - commonConfiguration(); - - _stateManager.attainState(State.INITIALISED); - } - - @Override - public void activate() throws Exception - { - if(_stateManager.isInState(State.INITIALISING)) - { - completeInitialisation(); - } - _stateManager.attainState(State.ACTIVATING); - - // this recovers durable exchanges, queues, and bindings - if(_configRecoveryHandler != null) - { - recoverConfiguration(_configRecoveryHandler); - } - if(_messageRecoveryHandler != null) - { - recoverMessages(_messageRecoveryHandler); - } - if(_tlogRecoveryHandler != null) - { - TransactionLogRecoveryHandler.DtxRecordRecoveryHandler dtxrh = recoverQueueEntries(_tlogRecoveryHandler); - recoverXids(dtxrh); - - } - - _stateManager.attainState(State.ACTIVE); - } - - private void commonConfiguration() - throws ClassNotFoundException, SQLException, AMQStoreException - { - implementationSpecificConfiguration(_virtualHost.getName(), _virtualHost); - createOrOpenDatabase(); - upgradeIfNecessary(); - } - - protected void upgradeIfNecessary() throws SQLException, AMQStoreException - { - Connection conn = newAutoCommitConnection(); - try - { - - PreparedStatement statement = conn.prepareStatement(SELECT_FROM_DB_VERSION); - try - { - ResultSet rs = statement.executeQuery(); - try - { - if(!rs.next()) - { - throw new AMQStoreException(DB_VERSION_TABLE_NAME + " does not contain the database version"); - } - int version = rs.getInt(1); - switch (version) - { - case 6: - upgradeFromV6(); - case DB_VERSION: - return; - default: - throw new AMQStoreException("Unknown database version: " + version); - } - } - finally - { - rs.close(); - } - } - finally - { - statement.close(); - } - } - finally - { - conn.close(); - } - - } - - private void upgradeFromV6() throws SQLException - { - updateDbVersion(7); - } - - private void updateDbVersion(int newVersion) throws SQLException - { - Connection conn = newAutoCommitConnection(); - try - { - - PreparedStatement statement = conn.prepareStatement(UPDATE_DB_VERSION); - try - { - statement.setInt(1,newVersion); - statement.execute(); - } - finally - { - statement.close(); - } - } - finally - { - conn.close(); - } - } - - protected abstract void implementationSpecificConfiguration(String name, - VirtualHost virtualHost) throws ClassNotFoundException, SQLException; - - abstract protected Logger getLogger(); - - abstract protected String getSqlBlobType(); - - abstract protected String getSqlVarBinaryType(int size); - - abstract protected String getSqlBigIntType(); - - protected void createOrOpenDatabase() throws SQLException - { - Connection conn = newAutoCommitConnection(); - - createVersionTable(conn); - createConfigVersionTable(conn); - createConfiguredObjectsTable(conn); - createQueueEntryTable(conn); - createMetaDataTable(conn); - createMessageContentTable(conn); - createLinkTable(conn); - createBridgeTable(conn); - createXidTable(conn); - createXidActionTable(conn); - conn.close(); - } - - private void createVersionTable(final Connection conn) throws SQLException - { - if(!tableExists(DB_VERSION_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute(CREATE_DB_VERSION_TABLE); - } - finally - { - stmt.close(); - } - - PreparedStatement pstmt = conn.prepareStatement(INSERT_INTO_DB_VERSION); - try - { - pstmt.setInt(1, DB_VERSION); - pstmt.execute(); - } - finally - { - pstmt.close(); - } - } - } - - private void createConfigVersionTable(final Connection conn) throws SQLException - { - if(!tableExists(CONFIGURATION_VERSION_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute(CREATE_CONFIG_VERSION_TABLE); - } - finally - { - stmt.close(); - } - - PreparedStatement pstmt = conn.prepareStatement(INSERT_INTO_CONFIG_VERSION); - try - { - pstmt.setInt(1, DEFAULT_CONFIG_VERSION); - pstmt.execute(); - } - finally - { - pstmt.close(); - } - } - } - - private void createConfiguredObjectsTable(final Connection conn) throws SQLException - { - if(!tableExists(CONFIGURED_OBJECTS_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("CREATE TABLE " + CONFIGURED_OBJECTS_TABLE_NAME - + " ( id VARCHAR(36) not null, object_type varchar(255), attributes "+getSqlBlobType()+", PRIMARY KEY (id))"); - } - finally - { - stmt.close(); - } - } - } - - - - private void createQueueEntryTable(final Connection conn) throws SQLException - { - if(!tableExists(QUEUE_ENTRY_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("CREATE TABLE "+ QUEUE_ENTRY_TABLE_NAME +" ( queue_id varchar(36) not null, message_id " - + getSqlBigIntType() + " not null, PRIMARY KEY (queue_id, message_id) )"); - } - finally - { - stmt.close(); - } - } - - } - - private void createMetaDataTable(final Connection conn) throws SQLException - { - if(!tableExists(META_DATA_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("CREATE TABLE " - + META_DATA_TABLE_NAME - + " ( message_id " - + getSqlBigIntType() - + " not null, meta_data " - + getSqlBlobType() - + ", PRIMARY KEY ( message_id ) )"); - } - finally - { - stmt.close(); - } - } - - } - - private void createMessageContentTable(final Connection conn) throws SQLException - { - if(!tableExists(MESSAGE_CONTENT_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("CREATE TABLE " - + MESSAGE_CONTENT_TABLE_NAME - + " ( message_id " - + getSqlBigIntType() - + " not null, content " - + getSqlBlobType() - + ", PRIMARY KEY (message_id) )"); - } - finally - { - stmt.close(); - } - } - - } - - private void createLinkTable(final Connection conn) throws SQLException - { - if(!tableExists(LINKS_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("CREATE TABLE "+ LINKS_TABLE_NAME +" ( id_lsb " + getSqlBigIntType() + " not null," - + " id_msb " + getSqlBigIntType() + " not null," - + " create_time " + getSqlBigIntType() + " not null," - + " arguments "+getSqlBlobType()+", PRIMARY KEY ( id_lsb, id_msb ))"); - } - finally - { - stmt.close(); - } - } - } - - private void createBridgeTable(final Connection conn) throws SQLException - { - if(!tableExists(BRIDGES_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("CREATE TABLE "+ BRIDGES_TABLE_NAME +" ( id_lsb " + getSqlBigIntType() + " not null," - + " id_msb " + getSqlBigIntType() + " not null," - + " create_time " + getSqlBigIntType() + " not null," - + " link_id_lsb " + getSqlBigIntType() + " not null," - + " link_id_msb " + getSqlBigIntType() + " not null," - + " arguments "+getSqlBlobType()+", PRIMARY KEY ( id_lsb, id_msb ))"); - } - finally - { - stmt.close(); - } - } - } - - private void createXidTable(final Connection conn) throws SQLException - { - if(!tableExists(XID_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("CREATE TABLE " - + XID_TABLE_NAME - + " ( format " + getSqlBigIntType() + " not null," - + " global_id " - + getSqlVarBinaryType(64) - + ", branch_id " - + getSqlVarBinaryType(64) - + " , PRIMARY KEY ( format, " - + - "global_id, branch_id ))"); - } - finally - { - stmt.close(); - } - } - } - - private void createXidActionTable(final Connection conn) throws SQLException - { - if(!tableExists(XID_ACTIONS_TABLE_NAME, conn)) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("CREATE TABLE " + XID_ACTIONS_TABLE_NAME + " ( format " + getSqlBigIntType() + " not null," - + " global_id " + getSqlVarBinaryType(64) + " not null, branch_id " + getSqlVarBinaryType( - 64) + " not null, " + - "action_type char not null, queue_id varchar(36) not null, message_id " + getSqlBigIntType() + " not null" + - ", PRIMARY KEY ( " + - "format, global_id, branch_id, action_type, queue_id, message_id))"); - } - finally - { - stmt.close(); - } - } - } - - protected boolean tableExists(final String tableName, final Connection conn) throws SQLException - { - DatabaseMetaData metaData = conn.getMetaData(); - ResultSet rs = metaData.getTables(null, null, "%", null); - - try - { - - while(rs.next()) - { - final String table = rs.getString(3); - if(tableName.equalsIgnoreCase(table)) - { - return true; - } - } - return false; - } - finally - { - rs.close(); - } - } - - protected void recoverConfiguration(ConfigurationRecoveryHandler recoveryHandler) throws AMQException - { - try - { - recoveryHandler.beginConfigurationRecovery(this, getConfigVersion()); - loadConfiguredObjects(recoveryHandler); - - setConfigVersion(recoveryHandler.completeConfigurationRecovery()); - } - catch (SQLException e) - { - throw new AMQStoreException("Error recovering persistent state: " + e.getMessage(), e); - } - } - - private void setConfigVersion(int version) throws SQLException - { - Connection conn = newAutoCommitConnection(); - try - { - - PreparedStatement stmt = conn.prepareStatement(UPDATE_CONFIG_VERSION); - try - { - stmt.setInt(1, version); - stmt.execute(); - - } - finally - { - stmt.close(); - } - } - finally - { - conn.close(); - } - } - - private int getConfigVersion() throws SQLException - { - Connection conn = newAutoCommitConnection(); - try - { - - Statement stmt = conn.createStatement(); - try - { - ResultSet rs = stmt.executeQuery(SELECT_FROM_CONFIG_VERSION); - try - { - - if(rs.next()) - { - return rs.getInt(1); - } - return DEFAULT_CONFIG_VERSION; - } - finally - { - rs.close(); - } - - } - finally - { - stmt.close(); - } - } - finally - { - conn.close(); - } - - } - - @Override - public void close() throws Exception - { - _closed.getAndSet(true); - _stateManager.attainState(State.CLOSING); - - doClose(); - - _stateManager.attainState(State.CLOSED); - } - - - protected abstract void doClose() throws Exception; - - @Override - public StoredMessage addMessage(StorableMessageMetaData metaData) - { - if(metaData.isPersistent()) - { - return new StoredJDBCMessage(_messageId.incrementAndGet(), metaData); - } - else - { - return new StoredMemoryMessage(_messageId.incrementAndGet(), metaData); - } - } - - public StoredMessage getMessage(long messageNumber) - { - return null; - } - - public void removeMessage(long messageId) - { - try - { - Connection conn = newConnection(); - try - { - PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_META_DATA); - try - { - stmt.setLong(1,messageId); - int results = stmt.executeUpdate(); - stmt.close(); - - if (results == 0) - { - getLogger().warn("Message metadata not found for message id " + messageId); - } - - if (getLogger().isDebugEnabled()) - { - getLogger().debug("Deleted metadata for message " + messageId); - } - - stmt = conn.prepareStatement(DELETE_FROM_MESSAGE_CONTENT); - stmt.setLong(1,messageId); - results = stmt.executeUpdate(); - } - finally - { - stmt.close(); - } - conn.commit(); - } - catch(SQLException e) - { - try - { - conn.rollback(); - } - catch(SQLException t) - { - // ignore - we are re-throwing underlying exception - } - - throw e; - - } - finally - { - conn.close(); - } - } - catch (SQLException e) - { - throw new RuntimeException("Error removing message with id " + messageId + " from database: " + e.getMessage(), e); - } - - } - - - @Override - public void create(UUID id, String type, Map<String,Object> attributes) throws AMQStoreException - { - if (_stateManager.isInState(State.ACTIVE)) - { - insertConfiguredObject(new ConfiguredObjectRecord(id, type, attributes)); - } - - } - - @Override - public void remove(UUID id, String type) throws AMQStoreException - { - int results = removeConfiguredObject(id); - if (results == 0) - { - throw new AMQStoreException(type + " with id " + id + " not found"); - } - } - - @Override - public void update(UUID id, String type, Map<String, Object> attributes) throws AMQStoreException - { - if (_stateManager.isInState(State.ACTIVE)) - { - ConfiguredObjectRecord queueConfiguredObject = loadConfiguredObject(id); - if (queueConfiguredObject != null) - { - ConfiguredObjectRecord newQueueRecord = new ConfiguredObjectRecord(id, type, attributes); - updateConfiguredObject(newQueueRecord); - } - } - - } - - /** - * Convenience method to create a new Connection configured for TRANSACTION_READ_COMMITED - * isolation and with auto-commit transactions enabled. - */ - protected Connection newAutoCommitConnection() throws SQLException - { - final Connection connection = newConnection(); - try - { - connection.setAutoCommit(true); - } - catch (SQLException sqlEx) - { - - try - { - connection.close(); - } - finally - { - throw sqlEx; - } - } - - return connection; - } - - /** - * Convenience method to create a new Connection configured for TRANSACTION_READ_COMMITED - * isolation and with auto-commit transactions disabled. - */ - protected Connection newConnection() throws SQLException - { - final Connection connection = getConnection(); - try - { - connection.setAutoCommit(false); - connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); - } - catch (SQLException sqlEx) - { - try - { - connection.close(); - } - finally - { - throw sqlEx; - } - } - return connection; - } - - protected abstract Connection getConnection() throws SQLException; - - private byte[] convertStringMapToBytes(final Map<String, String> arguments) throws AMQStoreException - { - byte[] argumentBytes; - if(arguments == null) - { - argumentBytes = new byte[0]; - } - else - { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(bos); - - - try - { - dos.writeInt(arguments.size()); - for(Map.Entry<String,String> arg : arguments.entrySet()) - { - dos.writeUTF(arg.getKey()); - dos.writeUTF(arg.getValue()); - } - } - catch (IOException e) - { - // This should never happen - throw new AMQStoreException(e.getMessage(), e); - } - argumentBytes = bos.toByteArray(); - } - return argumentBytes; - } - - @Override - public Transaction newTransaction() - { - return new JDBCTransaction(); - } - - public void enqueueMessage(ConnectionWrapper connWrapper, final TransactionLogResource queue, Long messageId) throws AMQStoreException - { - Connection conn = connWrapper.getConnection(); - - - try - { - if (getLogger().isDebugEnabled()) - { - getLogger().debug("Enqueuing message " - + messageId - + " on queue " - + (queue instanceof AMQQueue - ? ((AMQQueue) queue).getName() - : "") - + queue.getId() - + "[Connection" - + conn - + "]"); - } - - PreparedStatement stmt = conn.prepareStatement(INSERT_INTO_QUEUE_ENTRY); - try - { - stmt.setString(1, queue.getId().toString()); - stmt.setLong(2,messageId); - stmt.executeUpdate(); - } - finally - { - stmt.close(); - } - - } - catch (SQLException e) - { - getLogger().error("Failed to enqueue: " + e.getMessage(), e); - throw new AMQStoreException("Error writing enqueued message with id " + messageId + " for queue " + (queue instanceof AMQQueue ? ((AMQQueue)queue).getName() : "" ) + " with id " + queue.getId() - + " to database", e); - } - - } - - public void dequeueMessage(ConnectionWrapper connWrapper, final TransactionLogResource queue, Long messageId) throws AMQStoreException - { - - Connection conn = connWrapper.getConnection(); - - - try - { - PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_QUEUE_ENTRY); - try - { - stmt.setString(1, queue.getId().toString()); - stmt.setLong(2, messageId); - int results = stmt.executeUpdate(); - - - - if(results != 1) - { - throw new AMQStoreException("Unable to find message with id " + messageId + " on queue " + (queue instanceof AMQQueue ? ((AMQQueue)queue).getName() : "" ) - + " with id " + queue.getId()); - } - - if (getLogger().isDebugEnabled()) - { - getLogger().debug("Dequeuing message " + messageId + " on queue " + (queue instanceof AMQQueue - ? ((AMQQueue) queue).getName() - : "") - + " with id " + queue.getId()); - } - } - finally - { - stmt.close(); - } - - } - catch (SQLException e) - { - getLogger().error("Failed to dequeue: " + e.getMessage(), e); - throw new AMQStoreException("Error deleting enqueued message with id " + messageId + " for queue " + (queue instanceof AMQQueue ? ((AMQQueue)queue).getName() : "" ) - + " with id " + queue.getId() + " from database", e); - } - - } - - private void removeXid(ConnectionWrapper connWrapper, long format, byte[] globalId, byte[] branchId) - throws AMQStoreException - { - Connection conn = connWrapper.getConnection(); - - - try - { - PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_XIDS); - try - { - stmt.setLong(1,format); - stmt.setBytes(2,globalId); - stmt.setBytes(3,branchId); - int results = stmt.executeUpdate(); - - - - if(results != 1) - { - throw new AMQStoreException("Unable to find message with xid"); - } - } - finally - { - stmt.close(); - } - - stmt = conn.prepareStatement(DELETE_FROM_XID_ACTIONS); - try - { - stmt.setLong(1,format); - stmt.setBytes(2,globalId); - stmt.setBytes(3,branchId); - int results = stmt.executeUpdate(); - - } - finally - { - stmt.close(); - } - - } - catch (SQLException e) - { - getLogger().error("Failed to dequeue: " + e.getMessage(), e); - throw new AMQStoreException("Error deleting enqueued message with xid", e); - } - - } - - private void recordXid(ConnectionWrapper connWrapper, long format, byte[] globalId, byte[] branchId, - Transaction.Record[] enqueues, Transaction.Record[] dequeues) throws AMQStoreException - { - Connection conn = connWrapper.getConnection(); - - - try - { - - PreparedStatement stmt = conn.prepareStatement(INSERT_INTO_XIDS); - try - { - stmt.setLong(1,format); - stmt.setBytes(2, globalId); - stmt.setBytes(3, branchId); - stmt.executeUpdate(); - } - finally - { - stmt.close(); - } - - stmt = conn.prepareStatement(INSERT_INTO_XID_ACTIONS); - - try - { - stmt.setLong(1,format); - stmt.setBytes(2, globalId); - stmt.setBytes(3, branchId); - - if(enqueues != null) - { - stmt.setString(4, "E"); - for(Transaction.Record record : enqueues) - { - stmt.setString(5, record.getQueue().getId().toString()); - stmt.setLong(6, record.getMessage().getMessageNumber()); - stmt.executeUpdate(); - } - } - - if(dequeues != null) - { - stmt.setString(4, "D"); - for(Transaction.Record record : dequeues) - { - stmt.setString(5, record.getQueue().getId().toString()); - stmt.setLong(6, record.getMessage().getMessageNumber()); - stmt.executeUpdate(); - } - } - - } - finally - { - stmt.close(); - } - - } - catch (SQLException e) - { - getLogger().error("Failed to enqueue: " + e.getMessage(), e); - throw new AMQStoreException("Error writing xid ", e); - } - - } - - protected boolean isConfigStoreOnly() - { - return _messageRecoveryHandler == null; - } - - private static final class ConnectionWrapper - { - private final Connection _connection; - - public ConnectionWrapper(Connection conn) - { - _connection = conn; - } - - public Connection getConnection() - { - return _connection; - } - } - - - public void commitTran(ConnectionWrapper connWrapper) throws AMQStoreException - { - - try - { - Connection conn = connWrapper.getConnection(); - conn.commit(); - - if (getLogger().isDebugEnabled()) - { - getLogger().debug("commit tran completed"); - } - - conn.close(); - } - catch (SQLException e) - { - throw new AMQStoreException("Error commit tx: " + e.getMessage(), e); - } - finally - { - - } - } - - public StoreFuture commitTranAsync(ConnectionWrapper connWrapper) throws AMQStoreException - { - commitTran(connWrapper); - return StoreFuture.IMMEDIATE_FUTURE; - } - - public void abortTran(ConnectionWrapper connWrapper) throws AMQStoreException - { - if (connWrapper == null) - { - throw new AMQStoreException("Fatal internal error: transactional context is empty at abortTran"); - } - - if (getLogger().isDebugEnabled()) - { - getLogger().debug("abort tran called: " + connWrapper.getConnection()); - } - - try - { - Connection conn = connWrapper.getConnection(); - conn.rollback(); - conn.close(); - } - catch (SQLException e) - { - throw new AMQStoreException("Error aborting transaction: " + e.getMessage(), e); - } - - } - - public Long getNewMessageId() - { - return _messageId.incrementAndGet(); - } - - private void storeMetaData(Connection conn, long messageId, StorableMessageMetaData metaData) - throws SQLException - { - if(getLogger().isDebugEnabled()) - { - getLogger().debug("Adding metadata for message " + messageId); - } - - PreparedStatement stmt = conn.prepareStatement(INSERT_INTO_META_DATA); - try - { - stmt.setLong(1,messageId); - - final int bodySize = 1 + metaData.getStorableSize(); - byte[] underlying = new byte[bodySize]; - underlying[0] = (byte) metaData.getType().ordinal(); - ByteBuffer buf = ByteBuffer.wrap(underlying); - buf.position(1); - buf = buf.slice(); - - metaData.writeToBuffer(0, buf); - ByteArrayInputStream bis = new ByteArrayInputStream(underlying); - try - { - stmt.setBinaryStream(2,bis,underlying.length); - int result = stmt.executeUpdate(); - - if(result == 0) - { - throw new RuntimeException("Unable to add meta data for message " +messageId); - } - } - finally - { - try - { - bis.close(); - } - catch (IOException e) - { - - throw new SQLException(e); - } - } - - } - finally - { - stmt.close(); - } - - } - - protected void recoverMessages(MessageStoreRecoveryHandler recoveryHandler) throws SQLException - { - Connection conn = newAutoCommitConnection(); - try - { - MessageStoreRecoveryHandler.StoredMessageRecoveryHandler messageHandler = recoveryHandler.begin(); - - Statement stmt = conn.createStatement(); - try - { - ResultSet rs = stmt.executeQuery(SELECT_ALL_FROM_META_DATA); - try - { - - long maxId = 0; - - while(rs.next()) - { - - long messageId = rs.getLong(1); - if(messageId > maxId) - { - maxId = messageId; - } - - byte[] dataAsBytes = getBlobAsBytes(rs, 2); - - ByteBuffer buf = ByteBuffer.wrap(dataAsBytes); - buf.position(1); - buf = buf.slice(); - MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(dataAsBytes[0]); - StorableMessageMetaData metaData = type.createMetaData(buf); - StoredJDBCMessage message = new StoredJDBCMessage(messageId, metaData, true); - messageHandler.message(message); - } - - _messageId.set(maxId); - - messageHandler.completeMessageRecovery(); - } - finally - { - rs.close(); - } - } - finally - { - stmt.close(); - } - } - finally - { - conn.close(); - } - } - - - protected TransactionLogRecoveryHandler.DtxRecordRecoveryHandler recoverQueueEntries(TransactionLogRecoveryHandler recoveryHandler) throws SQLException - { - Connection conn = newAutoCommitConnection(); - try - { - TransactionLogRecoveryHandler.QueueEntryRecoveryHandler queueEntryHandler = recoveryHandler.begin(this); - - Statement stmt = conn.createStatement(); - try - { - ResultSet rs = stmt.executeQuery(SELECT_FROM_QUEUE_ENTRY); - try - { - while(rs.next()) - { - - String id = rs.getString(1); - long messageId = rs.getLong(2); - queueEntryHandler.queueEntry(UUID.fromString(id), messageId); - } - } - finally - { - rs.close(); - } - } - finally - { - stmt.close(); - } - - return queueEntryHandler.completeQueueEntryRecovery(); - } - finally - { - conn.close(); - } - } - - private static final class Xid - { - - private final long _format; - private final byte[] _globalId; - private final byte[] _branchId; - - public Xid(long format, byte[] globalId, byte[] branchId) - { - _format = format; - _globalId = globalId; - _branchId = branchId; - } - - public long getFormat() - { - return _format; - } - - public byte[] getGlobalId() - { - return _globalId; - } - - public byte[] getBranchId() - { - return _branchId; - } - } - - private static class RecordImpl implements Transaction.Record, TransactionLogResource, EnqueableMessage - { - - private long _messageNumber; - private UUID _queueId; - - public RecordImpl(UUID queueId, long messageNumber) - { - _messageNumber = messageNumber; - _queueId = queueId; - } - - @Override - public TransactionLogResource getQueue() - { - return this; - } - - @Override - public EnqueableMessage getMessage() - { - return this; - } - - @Override - public long getMessageNumber() - { - return _messageNumber; - } - - @Override - public boolean isPersistent() - { - return true; - } - - @Override - public StoredMessage getStoredMessage() - { - throw new UnsupportedOperationException(); - } - - @Override - public UUID getId() - { - return _queueId; - } - } - - protected void recoverXids(TransactionLogRecoveryHandler.DtxRecordRecoveryHandler dtxrh) throws SQLException - { - Connection conn = newAutoCommitConnection(); - try - { - List<Xid> xids = new ArrayList<Xid>(); - - Statement stmt = conn.createStatement(); - try - { - ResultSet rs = stmt.executeQuery(SELECT_ALL_FROM_XIDS); - try - { - while(rs.next()) - { - - long format = rs.getLong(1); - byte[] globalId = rs.getBytes(2); - byte[] branchId = rs.getBytes(3); - xids.add(new Xid(format, globalId, branchId)); - } - } - finally - { - rs.close(); - } - } - finally - { - stmt.close(); - } - - - - for(Xid xid : xids) - { - List<RecordImpl> enqueues = new ArrayList<RecordImpl>(); - List<RecordImpl> dequeues = new ArrayList<RecordImpl>(); - - PreparedStatement pstmt = conn.prepareStatement(SELECT_ALL_FROM_XID_ACTIONS); - - try - { - pstmt.setLong(1, xid.getFormat()); - pstmt.setBytes(2, xid.getGlobalId()); - pstmt.setBytes(3, xid.getBranchId()); - - ResultSet rs = pstmt.executeQuery(); - try - { - while(rs.next()) - { - - String actionType = rs.getString(1); - UUID queueId = UUID.fromString(rs.getString(2)); - long messageId = rs.getLong(3); - - RecordImpl record = new RecordImpl(queueId, messageId); - List<RecordImpl> records = "E".equals(actionType) ? enqueues : dequeues; - records.add(record); - } - } - finally - { - rs.close(); - } - } - finally - { - pstmt.close(); - } - - dtxrh.dtxRecord(xid.getFormat(), xid.getGlobalId(), xid.getBranchId(), - enqueues.toArray(new RecordImpl[enqueues.size()]), - dequeues.toArray(new RecordImpl[dequeues.size()])); - } - - - dtxrh.completeDtxRecordRecovery(); - } - finally - { - conn.close(); - } - - } - - StorableMessageMetaData getMetaData(long messageId) throws SQLException - { - - Connection conn = newAutoCommitConnection(); - try - { - PreparedStatement stmt = conn.prepareStatement(SELECT_FROM_META_DATA); - try - { - stmt.setLong(1,messageId); - ResultSet rs = stmt.executeQuery(); - try - { - - if(rs.next()) - { - byte[] dataAsBytes = getBlobAsBytes(rs, 1); - ByteBuffer buf = ByteBuffer.wrap(dataAsBytes); - buf.position(1); - buf = buf.slice(); - MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(dataAsBytes[0]); - StorableMessageMetaData metaData = type.createMetaData(buf); - - return metaData; - } - else - { - throw new RuntimeException("Meta data not found for message with id " + messageId); - } - } - finally - { - rs.close(); - } - } - finally - { - stmt.close(); - } - } - finally - { - conn.close(); - } - } - - protected abstract byte[] getBlobAsBytes(ResultSet rs, int col) throws SQLException; - - private void addContent(Connection conn, long messageId, ByteBuffer src) - { - if(getLogger().isDebugEnabled()) - { - getLogger().debug("Adding content for message " + messageId); - } - PreparedStatement stmt = null; - - try - { - src = src.slice(); - - byte[] chunkData = new byte[src.limit()]; - src.duplicate().get(chunkData); - - stmt = conn.prepareStatement(INSERT_INTO_MESSAGE_CONTENT); - stmt.setLong(1,messageId); - - ByteArrayInputStream bis = new ByteArrayInputStream(chunkData); - stmt.setBinaryStream(2, bis, chunkData.length); - stmt.executeUpdate(); - } - catch (SQLException e) - { - closeConnection(conn); - throw new RuntimeException("Error adding content for message " + messageId + ": " + e.getMessage(), e); - } - finally - { - closePreparedStatement(stmt); - } - - } - - public int getContent(long messageId, int offset, ByteBuffer dst) - { - Connection conn = null; - PreparedStatement stmt = null; - - try - { - conn = newAutoCommitConnection(); - - stmt = conn.prepareStatement(SELECT_FROM_MESSAGE_CONTENT); - stmt.setLong(1,messageId); - ResultSet rs = stmt.executeQuery(); - - int written = 0; - - if (rs.next()) - { - - byte[] dataAsBytes = getBlobAsBytes(rs, 1); - int size = dataAsBytes.length; - - if (offset > size) - { - throw new RuntimeException("Offset " + offset + " is greater than message size " + size - + " for message id " + messageId + "!"); - - } - - written = size - offset; - if(written > dst.remaining()) - { - written = dst.remaining(); - } - - dst.put(dataAsBytes, offset, written); - } - - return written; - - } - catch (SQLException e) - { - throw new RuntimeException("Error retrieving content from offset " + offset + " for message " + messageId + ": " + e.getMessage(), e); - } - finally - { - closePreparedStatement(stmt); - closeConnection(conn); - } - - - } - - @Override - public boolean isPersistent() - { - return true; - } - - - protected class JDBCTransaction implements Transaction - { - private final ConnectionWrapper _connWrapper; - private int _storeSizeIncrease; - - - protected JDBCTransaction() - { - try - { - _connWrapper = new ConnectionWrapper(newConnection()); - } - catch (SQLException e) - { - throw new RuntimeException(e); - } - } - - @Override - public void enqueueMessage(TransactionLogResource queue, EnqueableMessage message) throws AMQStoreException - { - final StoredMessage storedMessage = message.getStoredMessage(); - if(storedMessage instanceof StoredJDBCMessage) - { - try - { - ((StoredJDBCMessage) storedMessage).store(_connWrapper.getConnection()); - } - catch (SQLException e) - { - throw new AMQStoreException("Exception on enqueuing message " + _messageId, e); - } - } - _storeSizeIncrease += storedMessage.getMetaData().getContentSize(); - AbstractJDBCMessageStore.this.enqueueMessage(_connWrapper, queue, message.getMessageNumber()); - } - - @Override - public void dequeueMessage(TransactionLogResource queue, EnqueableMessage message) throws AMQStoreException - { - AbstractJDBCMessageStore.this.dequeueMessage(_connWrapper, queue, message.getMessageNumber()); - - } - - @Override - public void commitTran() throws AMQStoreException - { - AbstractJDBCMessageStore.this.commitTran(_connWrapper); - storedSizeChange(_storeSizeIncrease); - } - - @Override - public StoreFuture commitTranAsync() throws AMQStoreException - { - final StoreFuture storeFuture = AbstractJDBCMessageStore.this.commitTranAsync(_connWrapper); - storedSizeChange(_storeSizeIncrease); - return storeFuture; - } - - @Override - public void abortTran() throws AMQStoreException - { - AbstractJDBCMessageStore.this.abortTran(_connWrapper); - } - - @Override - public void removeXid(long format, byte[] globalId, byte[] branchId) throws AMQStoreException - { - AbstractJDBCMessageStore.this.removeXid(_connWrapper, format, globalId, branchId); - } - - @Override - public void recordXid(long format, byte[] globalId, byte[] branchId, Record[] enqueues, Record[] dequeues) - throws AMQStoreException - { - AbstractJDBCMessageStore.this.recordXid(_connWrapper, format, globalId, branchId, enqueues, dequeues); - } - } - - private class StoredJDBCMessage implements StoredMessage - { - - private final long _messageId; - private final boolean _isRecovered; - - private StorableMessageMetaData _metaData; - private volatile SoftReference<StorableMessageMetaData> _metaDataRef; - private byte[] _data; - private volatile SoftReference<byte[]> _dataRef; - - - StoredJDBCMessage(long messageId, StorableMessageMetaData metaData) - { - this(messageId, metaData, false); - } - - - StoredJDBCMessage(long messageId, - StorableMessageMetaData metaData, boolean isRecovered) - { - _messageId = messageId; - _isRecovered = isRecovered; - - if(!_isRecovered) - { - _metaData = metaData; - } - _metaDataRef = new SoftReference<StorableMessageMetaData>(metaData); - } - - @Override - public StorableMessageMetaData getMetaData() - { - StorableMessageMetaData metaData = _metaData == null ? _metaDataRef.get() : _metaData; - if(metaData == null) - { - try - { - metaData = AbstractJDBCMessageStore.this.getMetaData(_messageId); - } - catch (SQLException e) - { - throw new RuntimeException(e); - } - _metaDataRef = new SoftReference<StorableMessageMetaData>(metaData); - } - - return metaData; - } - - @Override - public long getMessageNumber() - { - return _messageId; - } - - @Override - public void addContent(int offsetInMessage, ByteBuffer src) - { - src = src.slice(); - - if(_data == null) - { - _data = new byte[src.remaining()]; - _dataRef = new SoftReference<byte[]>(_data); - src.duplicate().get(_data); - } - else - { - byte[] oldData = _data; - _data = new byte[oldData.length + src.remaining()]; - _dataRef = new SoftReference<byte[]>(_data); - - System.arraycopy(oldData,0,_data,0,oldData.length); - src.duplicate().get(_data, oldData.length, src.remaining()); - } - - } - - @Override - public int getContent(int offsetInMessage, ByteBuffer dst) - { - byte[] data = _dataRef == null ? null : _dataRef.get(); - if(data != null) - { - int length = Math.min(dst.remaining(), data.length - offsetInMessage); - dst.put(data, offsetInMessage, length); - return length; - } - else - { - return AbstractJDBCMessageStore.this.getContent(_messageId, offsetInMessage, dst); - } - } - - - @Override - public ByteBuffer getContent(int offsetInMessage, int size) - { - ByteBuffer buf = ByteBuffer.allocate(size); - int length = getContent(offsetInMessage, buf); - buf.position(0); - buf.limit(length); - return buf; - } - - @Override - public synchronized StoreFuture flushToStore() - { - Connection conn = null; - try - { - if(!stored()) - { - conn = newConnection(); - - store(conn); - - conn.commit(); - storedSizeChange(getMetaData().getContentSize()); - } - } - catch (SQLException e) - { - if(getLogger().isDebugEnabled()) - { - getLogger().debug("Error when trying to flush message " + _messageId + " to store: " + e); - } - throw new RuntimeException(e); - } - finally - { - closeConnection(conn); - } - return StoreFuture.IMMEDIATE_FUTURE; - } - - @Override - public void remove() - { - int delta = getMetaData().getContentSize(); - AbstractJDBCMessageStore.this.removeMessage(_messageId); - storedSizeChange(-delta); - } - - private synchronized void store(final Connection conn) throws SQLException - { - if (!stored()) - { - try - { - storeMetaData(conn, _messageId, _metaData); - AbstractJDBCMessageStore.this.addContent(conn, _messageId, - _data == null ? ByteBuffer.allocate(0) : ByteBuffer.wrap(_data)); - } - finally - { - _metaData = null; - _data = null; - } - - if(getLogger().isDebugEnabled()) - { - getLogger().debug("Storing message " + _messageId + " to store"); - } - } - } - - private boolean stored() - { - return _metaData == null || _isRecovered; - } - } - - protected void closeConnection(final Connection conn) - { - if(conn != null) - { - try - { - conn.close(); - } - catch (SQLException e) - { - getLogger().error("Problem closing connection", e); - } - } - } - - protected void closePreparedStatement(final PreparedStatement stmt) - { - if (stmt != null) - { - try - { - stmt.close(); - } - catch(SQLException e) - { - getLogger().error("Problem closing prepared statement", e); - } - } - } - - @Override - public void addEventListener(EventListener eventListener, Event... events) - { - _eventManager.addEventListener(eventListener, events); - } - - private void insertConfiguredObject(ConfiguredObjectRecord configuredObject) throws AMQStoreException - { - if (_stateManager.isInState(State.ACTIVE)) - { - try - { - Connection conn = newAutoCommitConnection(); - try - { - PreparedStatement stmt = conn.prepareStatement(FIND_CONFIGURED_OBJECT); - try - { - stmt.setString(1, configuredObject.getId().toString()); - ResultSet rs = stmt.executeQuery(); - try - { - // If we don't have any data in the result set then we can add this configured object - if (!rs.next()) - { - PreparedStatement insertStmt = conn.prepareStatement(INSERT_INTO_CONFIGURED_OBJECTS); - try - { - insertStmt.setString(1, configuredObject.getId().toString()); - insertStmt.setString(2, configuredObject.getType()); - if(configuredObject.getAttributes() == null) - { - insertStmt.setNull(3, Types.BLOB); - } - else - { - final Map<String, Object> attributes = configuredObject.getAttributes(); - byte[] attributesAsBytes = new ObjectMapper().writeValueAsBytes(attributes); - ByteArrayInputStream bis = new ByteArrayInputStream(attributesAsBytes); - insertStmt.setBinaryStream(3, bis, attributesAsBytes.length); - } - insertStmt.execute(); - } - finally - { - insertStmt.close(); - } - } - } - finally - { - rs.close(); - } - } - finally - { - stmt.close(); - } - } - finally - { - conn.close(); - } - } - catch (JsonMappingException e) - { - throw new AMQStoreException("Error inserting of configured object " + configuredObject + " into database: " + e.getMessage(), e); - } - catch (JsonGenerationException e) - { - throw new AMQStoreException("Error inserting of configured object " + configuredObject + " into database: " + e.getMessage(), e); - } - catch (IOException e) - { - throw new AMQStoreException("Error inserting of configured object " + configuredObject + " into database: " + e.getMessage(), e); - } - catch (SQLException e) - { - throw new AMQStoreException("Error inserting of configured object " + configuredObject + " into database: " + e.getMessage(), e); - } - } - } - - private int removeConfiguredObject(UUID id) throws AMQStoreException - { - int results = 0; - try - { - Connection conn = newAutoCommitConnection(); - try - { - results = removeConfiguredObject(id, conn); - } - finally - { - conn.close(); - } - } - catch (SQLException e) - { - throw new AMQStoreException("Error deleting of configured object with id " + id + " from database: " + e.getMessage(), e); - } - return results; - } - - public UUID[] removeConfiguredObjects(UUID... objects) throws AMQStoreException - { - Collection<UUID> removed = new ArrayList<UUID>(objects.length); - try - { - - Connection conn = newAutoCommitConnection(); - try - { - for(UUID id : objects) - { - if(removeConfiguredObject(id, conn) != 0) - { - removed.add(id); - } - } - } - finally - { - conn.close(); - } - } - catch (SQLException e) - { - throw new AMQStoreException("Error deleting of configured objects " + Arrays.asList(objects) + " from database: " + e.getMessage(), e); - } - return removed.toArray(new UUID[removed.size()]); - } - - private int removeConfiguredObject(final UUID id, final Connection conn) throws SQLException - { - final int results;PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_CONFIGURED_OBJECTS); - try - { - stmt.setString(1, id.toString()); - results = stmt.executeUpdate(); - } - finally - { - stmt.close(); - } - return results; - } - - private void updateConfiguredObject(final ConfiguredObjectRecord configuredObject) throws AMQStoreException - { - if (_stateManager.isInState(State.ACTIVE)) - { - try - { - Connection conn = newAutoCommitConnection(); - try - { - updateConfiguredObject(configuredObject, false, conn); - } - finally - { - conn.close(); - } - } - catch (SQLException e) - { - throw new AMQStoreException("Error updating configured object " + configuredObject + " in database: " + e.getMessage(), e); - } - } - } - - @Override - public void update(ConfiguredObjectRecord... records) throws AMQStoreException - { - update(false, records); - } - - public void update(boolean createIfNecessary, ConfiguredObjectRecord... records) throws AMQStoreException - { - if (_stateManager.isInState(State.ACTIVE) || _stateManager.isInState(State.ACTIVATING)) - { - try - { - Connection conn = newConnection(); - try - { - for(ConfiguredObjectRecord record : records) - { - updateConfiguredObject(record, createIfNecessary, conn); - } - conn.commit(); - } - finally - { - conn.close(); - } - } - catch (SQLException e) - { - throw new AMQStoreException("Error updating configured objects in database: " + e.getMessage(), e); - } - - } - - } - - private void updateConfiguredObject(ConfiguredObjectRecord configuredObject, - boolean createIfNecessary, - Connection conn) - throws SQLException, AMQStoreException - { - PreparedStatement stmt = conn.prepareStatement(FIND_CONFIGURED_OBJECT); - try - { - stmt.setString(1, configuredObject.getId().toString()); - ResultSet rs = stmt.executeQuery(); - try - { - if (rs.next()) - { - PreparedStatement stmt2 = conn.prepareStatement(UPDATE_CONFIGURED_OBJECTS); - try - { - stmt2.setString(1, configuredObject.getType()); - if (configuredObject.getAttributes() != null) - { - byte[] attributesAsBytes = (new ObjectMapper()).writeValueAsBytes( - configuredObject.getAttributes()); - ByteArrayInputStream bis = new ByteArrayInputStream(attributesAsBytes); - stmt2.setBinaryStream(2, bis, attributesAsBytes.length); - } - else - { - stmt2.setNull(2, Types.BLOB); - } - stmt2.setString(3, configuredObject.getId().toString()); - stmt2.execute(); - } - finally - { - stmt2.close(); - } - } - else if(createIfNecessary) - { - PreparedStatement insertStmt = conn.prepareStatement(INSERT_INTO_CONFIGURED_OBJECTS); - try - { - insertStmt.setString(1, configuredObject.getId().toString()); - insertStmt.setString(2, configuredObject.getType()); - if(configuredObject.getAttributes() == null) - { - insertStmt.setNull(3, Types.BLOB); - } - else - { - final Map<String, Object> attributes = configuredObject.getAttributes(); - byte[] attributesAsBytes = new ObjectMapper().writeValueAsBytes(attributes); - ByteArrayInputStream bis = new ByteArrayInputStream(attributesAsBytes); - insertStmt.setBinaryStream(3, bis, attributesAsBytes.length); - } - insertStmt.execute(); - } - finally - { - insertStmt.close(); - } - } - } - finally - { - rs.close(); - } - } - catch (JsonMappingException e) - { - throw new AMQStoreException("Error updating configured object " + configuredObject + " in database: " + e.getMessage(), e); - } - catch (JsonGenerationException e) - { - throw new AMQStoreException("Error updating configured object " + configuredObject + " in database: " + e.getMessage(), e); - } - catch (IOException e) - { - throw new AMQStoreException("Error updating configured object " + configuredObject + " in database: " + e.getMessage(), e); - } - finally - { - stmt.close(); - } - - } - - private ConfiguredObjectRecord loadConfiguredObject(final UUID id) throws AMQStoreException - { - ConfiguredObjectRecord result = null; - try - { - Connection conn = newAutoCommitConnection(); - try - { - PreparedStatement stmt = conn.prepareStatement(FIND_CONFIGURED_OBJECT); - try - { - stmt.setString(1, id.toString()); - ResultSet rs = stmt.executeQuery(); - try - { - if (rs.next()) - { - String type = rs.getString(1); - String attributes = getBlobAsString(rs, 2); - result = new ConfiguredObjectRecord(id, type, - (new ObjectMapper()).readValue(attributes,Map.class)); - } - } - finally - { - rs.close(); - } - } - finally - { - stmt.close(); - } - } - finally - { - conn.close(); - } - } - catch (JsonMappingException e) - { - throw new AMQStoreException("Error loading of configured object with id " + id + " from database: " - + e.getMessage(), e); - } - catch (JsonParseException e) - { - throw new AMQStoreException("Error loading of configured object with id " + id + " from database: " - + e.getMessage(), e); - } - catch (IOException e) - { - throw new AMQStoreException("Error loading of configured object with id " + id + " from database: " - + e.getMessage(), e); - } - catch (SQLException e) - { - throw new AMQStoreException("Error loading of configured object with id " + id + " from database: " - + e.getMessage(), e); - } - return result; - } - - private void loadConfiguredObjects(ConfigurationRecoveryHandler recoveryHandler) throws SQLException, AMQStoreException - { - Connection conn = newAutoCommitConnection(); - - final ObjectMapper objectMapper = new ObjectMapper(); - try - { - PreparedStatement stmt = conn.prepareStatement(SELECT_FROM_CONFIGURED_OBJECTS); - try - { - ResultSet rs = stmt.executeQuery(); - try - { - while (rs.next()) - { - String id = rs.getString(1); - String objectType = rs.getString(2); - String attributes = getBlobAsString(rs, 3); - recoveryHandler.configuredObject(UUID.fromString(id), objectType, - objectMapper.readValue(attributes,Map.class)); - } - } - catch (JsonMappingException e) - { - throw new AMQStoreException("Error recovering persistent state: " + e.getMessage(), e); - } - catch (JsonParseException e) - { - throw new AMQStoreException("Error recovering persistent state: " + e.getMessage(), e); - } - catch (IOException e) - { - throw new AMQStoreException("Error recovering persistent state: " + e.getMessage(), e); - } - finally - { - rs.close(); - } - } - finally - { - stmt.close(); - } - } - finally - { - conn.close(); - } - } - - protected abstract String getBlobAsString(ResultSet rs, int col) throws SQLException; - - protected abstract void storedSizeChange(int storeSizeIncrease); - - - @Override - public void onDelete() - { - try - { - Connection conn = newAutoCommitConnection(); - try - { - for (String tableName : ALL_TABLES) - { - Statement stmt = conn.createStatement(); - try - { - stmt.execute("DROP TABLE " + tableName); - } - finally - { - stmt.close(); - } - } - } - finally - { - conn.close(); - } - } - catch(SQLException e) - { - getLogger().error("Exception while deleting store tables", e); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractMemoryMessageStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractMemoryMessageStore.java deleted file mode 100644 index 3abf083026..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/AbstractMemoryMessageStore.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.model.VirtualHost; - -/** A simple message store that stores the messages in a thread-safe structure in memory. */ -abstract public class AbstractMemoryMessageStore extends NullMessageStore -{ - private final AtomicLong _messageId = new AtomicLong(1); - private final AtomicBoolean _closed = new AtomicBoolean(false); - - private static final Transaction IN_MEMORY_TRANSACTION = new Transaction() - { - @Override - public StoreFuture commitTranAsync() throws AMQStoreException - { - return StoreFuture.IMMEDIATE_FUTURE; - } - - @Override - public void enqueueMessage(TransactionLogResource queue, EnqueableMessage message) throws AMQStoreException - { - } - - @Override - public void dequeueMessage(TransactionLogResource queue, EnqueableMessage message) throws AMQStoreException - { - } - - @Override - public void commitTran() throws AMQStoreException - { - } - - @Override - public void abortTran() throws AMQStoreException - { - } - - @Override - public void removeXid(long format, byte[] globalId, byte[] branchId) - { - } - - @Override - public void recordXid(long format, byte[] globalId, byte[] branchId, Record[] enqueues, Record[] dequeues) - { - } - }; - - private final StateManager _stateManager; - private final EventManager _eventManager = new EventManager(); - - public AbstractMemoryMessageStore() - { - _stateManager = new StateManager(_eventManager); - } - - @Override - public void configureConfigStore(VirtualHost virtualHost, ConfigurationRecoveryHandler recoveryHandler) throws Exception - { - _stateManager.attainState(State.INITIALISING); - } - - @Override - public void configureMessageStore(VirtualHost virtualHost, MessageStoreRecoveryHandler recoveryHandler, - TransactionLogRecoveryHandler tlogRecoveryHandler) throws Exception - { - if(_stateManager.isInState(State.INITIAL)) - { - _stateManager.attainState(State.INITIALISING); - } - _stateManager.attainState(State.INITIALISED); - } - - @Override - public void activate() throws Exception - { - - if(_stateManager.isInState(State.INITIALISING)) - { - _stateManager.attainState(State.INITIALISED); - } - _stateManager.attainState(State.ACTIVATING); - - _stateManager.attainState(State.ACTIVE); - } - - @Override - public StoredMessage addMessage(StorableMessageMetaData metaData) - { - final long id = _messageId.getAndIncrement(); - StoredMemoryMessage message = new StoredMemoryMessage(id, metaData); - - return message; - } - - @Override - public Transaction newTransaction() - { - return IN_MEMORY_TRANSACTION; - } - - @Override - public boolean isPersistent() - { - return false; - } - - @Override - public void close() throws Exception - { - _stateManager.attainState(State.CLOSING); - _closed.getAndSet(true); - _stateManager.attainState(State.CLOSED); - } - - @Override - public void addEventListener(EventListener eventListener, Event... events) - { - _eventManager.addEventListener(eventListener, events); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/ConfigurationRecoveryHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/ConfigurationRecoveryHandler.java deleted file mode 100755 index a3534d3fa5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/ConfigurationRecoveryHandler.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.store; - -import org.apache.qpid.framing.FieldTable; - -import java.nio.ByteBuffer; -import java.util.Map; -import java.util.UUID; - -public interface ConfigurationRecoveryHandler -{ - void beginConfigurationRecovery(DurableConfigurationStore store, int configVersion); - - void configuredObject(UUID id, String type, Map<String, Object> attributes); - - /** - * - * @return the model version of the configuration - */ - int completeConfigurationRecovery(); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/ConfiguredObjectRecord.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/ConfiguredObjectRecord.java deleted file mode 100644 index 44490385d9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/ConfiguredObjectRecord.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; - -public class ConfiguredObjectRecord -{ - private UUID _id; - private String _type; - private Map<String,Object> _attributes; - - public ConfiguredObjectRecord(UUID id, String type, Map<String,Object> attributes) - { - super(); - _id = id; - _type = type; - _attributes = Collections.unmodifiableMap(new LinkedHashMap<String,Object>(attributes)); - } - - public UUID getId() - { - return _id; - } - - public String getType() - { - return _type; - } - - public Map<String,Object> getAttributes() - { - return _attributes; - } - - @Override - public String toString() - { - return "ConfiguredObjectRecord [id=" + _id + ", type=" + _type + ", attributes=" + _attributes + "]"; - } - - @Override - public boolean equals(Object o) - { - if(this == o) - { - return true; - } - if(o == null || getClass() != o.getClass()) - { - return false; - } - - ConfiguredObjectRecord that = (ConfiguredObjectRecord) o; - - return _type.equals(that._type) && _id.equals(that._id) && _attributes.equals(that._attributes); - } - - @Override - public int hashCode() - { - int result = _id.hashCode(); - result = 31 * result + _type.hashCode(); - result = 31 * result + _attributes.hashCode(); - return result; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DependencyListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DependencyListener.java deleted file mode 100644 index 120c904cf7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DependencyListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.UUID; - -interface DependencyListener -{ - void dependencyResolved(String type, UUID id, Object o); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationRecoverer.java deleted file mode 100644 index 7fb80bde96..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationRecoverer.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.ConfigStoreMessages; -import org.apache.qpid.server.logging.subjects.MessageStoreLogSubject; - -import static org.apache.qpid.server.model.VirtualHost.CURRENT_CONFIG_VERSION; - -public class DurableConfigurationRecoverer implements ConfigurationRecoveryHandler -{ - private static final Logger _logger = Logger.getLogger(DurableConfigurationRecoverer.class); - - private final Map<String, Map<UUID, Object>> _resolvedObjects = new HashMap<String, Map<UUID, Object>>(); - - private final Map<String, Map<UUID, UnresolvedObject>> _unresolvedObjects = - new HashMap<String, Map<UUID, UnresolvedObject>>(); - - private final Map<String, Map<UUID, List<DependencyListener>>> _dependencyListeners = - new HashMap<String, Map<UUID, List<DependencyListener>>>(); - private final Map<String, DurableConfiguredObjectRecoverer> _recoverers; - private final UpgraderProvider _upgraderProvider; - - private DurableConfigurationStoreUpgrader _upgrader; - - private DurableConfigurationStore _store; - private final String _name; - - private MessageStoreLogSubject _logSubject; - - public DurableConfigurationRecoverer(final String name, - Map<String, DurableConfiguredObjectRecoverer> recoverers, - UpgraderProvider upgraderProvider) - { - _recoverers = recoverers; - _name = name; - _upgraderProvider = upgraderProvider; - } - - @Override - public void beginConfigurationRecovery(final DurableConfigurationStore store, final int configVersion) - { - _logSubject = new MessageStoreLogSubject(_name, store.getClass().getSimpleName()); - - _store = store; - _upgrader = _upgraderProvider.getUpgrader(configVersion, this); - } - - @Override - public void configuredObject(final UUID id, final String type, final Map<String, Object> attributes) - { - _upgrader.configuredObject(id, type, attributes); - } - - void onConfiguredObject(final UUID id, final String type, final Map<String, Object> attributes) - { - DurableConfiguredObjectRecoverer recoverer = getRecoverer(type); - if(recoverer == null) - { - throw new IllegalConfigurationException("Unkown type for configured object: " + type); - } - recoverer.load(this, id, attributes); - } - - private DurableConfiguredObjectRecoverer getRecoverer(final String type) - { - DurableConfiguredObjectRecoverer recoverer = _recoverers.get(type); - return recoverer; - } - - @Override - public int completeConfigurationRecovery() - { - _upgrader.complete(); - checkUnresolvedDependencies(); - applyUpgrade(); - - CurrentActor.get().message(_logSubject, ConfigStoreMessages.RECOVERY_COMPLETE()); - return CURRENT_CONFIG_VERSION; - } - - private void applyUpgrade() - { - - final Collection<ConfiguredObjectRecord> updates = new ArrayList<ConfiguredObjectRecord>(); - final Collection<UUID> deletes = new ArrayList<UUID>(); - for(Map.Entry<UUID,ConfiguredObjectRecord> entry : _upgrader.getUpdatedRecords().entrySet()) - { - if(entry.getValue() != null) - { - updates.add(entry.getValue()); - } - else - { - deletes.add(entry.getKey()); - } - } - - try - { - if(!updates.isEmpty()) - { - _store.update(true,updates.toArray(new ConfiguredObjectRecord[updates.size()])); - } - if(!deletes.isEmpty()) - { - _store.removeConfiguredObjects(deletes.toArray(new UUID[deletes.size()])); - } - } - catch (AMQStoreException e) - { - // TODO better exception - throw new RuntimeException("Unable to update config store when upgrading"); - } - - } - - private void checkUnresolvedDependencies() - { - if(_unresolvedObjects != null && !_unresolvedObjects.isEmpty()) - { - boolean unresolvedObjectsExist = false; - for(Map.Entry<String, Map<UUID, UnresolvedObject>>entry : _unresolvedObjects.entrySet()) - { - for(Map.Entry<UUID,UnresolvedObject> obj : entry.getValue().entrySet()) - { - unresolvedObjectsExist = true; - StringBuilder errorMessage = new StringBuilder("Durable configured object of type "); - errorMessage.append(entry.getKey()).append(" with id ").append(obj.getKey()) - .append(" has unresolved dependencies: "); - for(UnresolvedDependency dep : obj.getValue().getUnresolvedDependencies()) - { - errorMessage.append(dep.getType()).append(" with id ").append(dep.getId()).append("; "); - } - _logger.error(errorMessage); - } - } - if(unresolvedObjectsExist) - { - throw new IllegalConfigurationException("Durable configuration has unresolved dependencies"); - } - } - } - - void addResolutionListener(final String type, - final UUID id, - final DependencyListener dependencyListener) - { - Map<UUID, List<DependencyListener>> typeListeners = _dependencyListeners.get(type); - if(typeListeners == null) - { - typeListeners = new HashMap<UUID, List<DependencyListener>>(); - _dependencyListeners.put(type, typeListeners); - } - List<DependencyListener> objectListeners = typeListeners.get(id); - if(objectListeners == null) - { - objectListeners = new ArrayList<DependencyListener>(); - typeListeners.put(id, objectListeners); - } - objectListeners.add(dependencyListener); - - } - - Object getResolvedObject(final String type, final UUID id) - { - Map<UUID, Object> objects = _resolvedObjects.get(type); - return objects == null ? null : objects.get(id); - } - - void resolve(final String type, final UUID id, final Object object) - { - Map<UUID, Object> typeObjects = _resolvedObjects.get(type); - if(typeObjects == null) - { - typeObjects = new HashMap<UUID, Object>(); - _resolvedObjects.put(type, typeObjects); - } - typeObjects.put(id, object); - Map<UUID, UnresolvedObject> unresolved = _unresolvedObjects.get(type); - if(unresolved != null) - { - unresolved.remove(id); - } - - Map<UUID, List<DependencyListener>> typeListeners = _dependencyListeners.get(type); - if(typeListeners != null) - { - List<DependencyListener> listeners = typeListeners.remove(id); - if(listeners != null) - { - for(DependencyListener listener : listeners) - { - listener.dependencyResolved(type, id, object); - } - } - } - } - - void addUnresolvedObject(final String type, - final UUID id, - final UnresolvedObject obj) - { - Map<UUID, UnresolvedObject> typeObjects = _unresolvedObjects.get(type); - if(typeObjects == null) - { - typeObjects = new HashMap<UUID, UnresolvedObject>(); - _unresolvedObjects.put(type, typeObjects); - } - typeObjects.put(id, obj); - } - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStore.java deleted file mode 100755 index 6b0748b0c3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStore.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Map; -import java.util.UUID; -import org.apache.commons.configuration.Configuration; - -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.queue.AMQQueue; - -public interface DurableConfigurationStore -{ - - public static interface Source - { - DurableConfigurationStore getDurableConfigurationStore(); - } - - /** - * Called after instantiation in order to configure the message store. A particular implementation can define - * whatever parameters it wants. - * - * - * - * - * - * @param virtualHost - * @param recoveryHandler Handler to be called as the store recovers on start up - * @throws Exception If any error occurs that means the store is unable to configure itself. - */ - void configureConfigStore(VirtualHost virtualHost, ConfigurationRecoveryHandler recoveryHandler) throws Exception; - - - /** - * Makes the specified object persistent. - * - * @param id The id of the object to persist. - * @param type The type of the object to persist - * @param attributes the attributes of the object to persist - * - * @throws AMQStoreException If the operation fails for any reason. - */ - void create(UUID id, String type, Map<String, Object> attributes) throws AMQStoreException; - - /** - * Removes the specified persistent configured object. - * - * @param id The id of the object to remove. - * @param type The type of the object to remove - * - * @throws AMQStoreException If the operation fails for any reason. - */ - void remove(UUID id, String type) throws AMQStoreException; - - public UUID[] removeConfiguredObjects(UUID... objects) throws AMQStoreException; - - - /** - * Updates the specified object in the persistent store, IF it is already present. If the object - * is not present in the store, it will not be added. - * - * @param id The id of the object to update. - * @param type The type of the object to update - * @param attributes the updated attributes - * - * @throws AMQStoreException If the operation fails for any reason. - */ - void update(UUID id, String type, Map<String, Object> attributes) throws AMQStoreException; - - - public void update(ConfiguredObjectRecord... records) throws AMQStoreException; - public void update(boolean createIfNecessary, ConfiguredObjectRecord... records) throws AMQStoreException; - - - void close() throws Exception; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreCreator.java deleted file mode 100644 index 3a69f802f0..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreCreator.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.plugin.DurableConfigurationStoreFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class DurableConfigurationStoreCreator -{ - private Map<String, DurableConfigurationStoreFactory> _factories = new HashMap<String, DurableConfigurationStoreFactory>(); - - public DurableConfigurationStoreCreator() - { - QpidServiceLoader<DurableConfigurationStoreFactory> qpidServiceLoader = new QpidServiceLoader<DurableConfigurationStoreFactory>(); - Iterable<DurableConfigurationStoreFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(DurableConfigurationStoreFactory.class); - for (DurableConfigurationStoreFactory durableConfigurationStoreFactory : factories) - { - String type = durableConfigurationStoreFactory.getType(); - DurableConfigurationStoreFactory factory = _factories.put(type.toLowerCase(), durableConfigurationStoreFactory); - if (factory != null) - { - throw new IllegalStateException("DurableConfigurationStoreFactory with type name '" + type - + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '" - + durableConfigurationStoreFactory.getClass().getName() + "'"); - } - } - } - - public boolean isValidType(String storeType) - { - return _factories.containsKey(storeType.toLowerCase()); - } - - - public DurableConfigurationStore createMessageStore(String storeType) - { - DurableConfigurationStoreFactory factory = _factories.get(storeType.toLowerCase()); - if (factory == null) - { - throw new IllegalConfigurationException("Unknown store type: " + storeType - + ". Supported types: " + _factories.keySet()); - } - return factory.createDurableConfigurationStore(); - } - - public Collection<DurableConfigurationStoreFactory> getFactories() - { - return Collections.unmodifiableCollection(_factories.values()); - } - - public Collection<String> getStoreTypes() - { - return Collections.unmodifiableCollection(_factories.keySet()); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreHelper.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreHelper.java deleted file mode 100644 index d311685375..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreHelper.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Map; - -import java.util.Set; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.model.Binding; -import org.apache.qpid.server.model.Exchange; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.QueueArgumentsConverter; - -public class DurableConfigurationStoreHelper -{ - - private static final String BINDING = Binding.class.getSimpleName(); - private static final String EXCHANGE = Exchange.class.getSimpleName(); - private static final String QUEUE = Queue.class.getSimpleName(); - private static final Set<String> QUEUE_ARGUMENTS_EXCLUDES = new HashSet<String>(Arrays.asList(Queue.NAME, - Queue.OWNER, - Queue.EXCLUSIVE, - Queue.ALTERNATE_EXCHANGE)); - - public static void updateQueue(DurableConfigurationStore store, AMQQueue queue) throws AMQStoreException - { - Map<String, Object> attributesMap = new LinkedHashMap<String, Object>(); - attributesMap.put(Queue.NAME, queue.getName()); - attributesMap.put(Queue.OWNER, queue.getOwner()); - attributesMap.put(Queue.EXCLUSIVE, queue.isExclusive()); - - if (queue.getAlternateExchange() != null) - { - attributesMap.put(Queue.ALTERNATE_EXCHANGE, queue.getAlternateExchange().getId()); - } - - Collection<String> availableAttrs = queue.getAvailableAttributes(); - - for(String attrName : availableAttrs) - { - if(!QUEUE_ARGUMENTS_EXCLUDES.contains(attrName)) - { - attributesMap.put(attrName, queue.getAttribute(attrName)); - } - } - - store.update(queue.getId(), QUEUE, attributesMap); - } - - public static void createQueue(DurableConfigurationStore store, AMQQueue queue) - throws AMQStoreException - { - Map<String, Object> attributesMap = new HashMap<String, Object>(); - attributesMap.put(Queue.NAME, queue.getName()); - attributesMap.put(Queue.OWNER, queue.getOwner()); - attributesMap.put(Queue.EXCLUSIVE, queue.isExclusive()); - if (queue.getAlternateExchange() != null) - { - attributesMap.put(Queue.ALTERNATE_EXCHANGE, queue.getAlternateExchange().getId()); - } - - for(String attrName : queue.getAvailableAttributes()) - { - if(!QUEUE_ARGUMENTS_EXCLUDES.contains(attrName)) - { - attributesMap.put(attrName, queue.getAttribute(attrName)); - } - } - store.create(queue.getId(), QUEUE,attributesMap); - } - - public static void removeQueue(DurableConfigurationStore store, AMQQueue queue) throws AMQStoreException - { - store.remove(queue.getId(), QUEUE); - } - - public static void createExchange(DurableConfigurationStore store, org.apache.qpid.server.exchange.Exchange exchange) - throws AMQStoreException - { - Map<String, Object> attributesMap = new HashMap<String, Object>(); - attributesMap.put(Exchange.NAME, exchange.getName()); - attributesMap.put(Exchange.TYPE, exchange.getTypeName()); - attributesMap.put(Exchange.LIFETIME_POLICY, exchange.isAutoDelete() ? LifetimePolicy.AUTO_DELETE.name() - : LifetimePolicy.PERMANENT.name()); - store.create(exchange.getId(), EXCHANGE, attributesMap); - - } - - - public static void removeExchange(DurableConfigurationStore store, org.apache.qpid.server.exchange.Exchange exchange) - throws AMQStoreException - { - store.remove(exchange.getId(), EXCHANGE); - } - - public static void createBinding(DurableConfigurationStore store, org.apache.qpid.server.binding.Binding binding) - throws AMQStoreException - { - Map<String, Object> attributesMap = new HashMap<String, Object>(); - attributesMap.put(Binding.NAME, binding.getBindingKey()); - attributesMap.put(Binding.EXCHANGE, binding.getExchange().getId()); - attributesMap.put(Binding.QUEUE, binding.getQueue().getId()); - Map<String, Object> arguments = binding.getArguments(); - if (arguments != null) - { - attributesMap.put(Binding.ARGUMENTS, arguments); - } - store.create(binding.getId(), BINDING, attributesMap); - } - - - public static void removeBinding(DurableConfigurationStore store, org.apache.qpid.server.binding.Binding binding) - throws AMQStoreException - { - store.remove(binding.getId(), BINDING); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreUpgrader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreUpgrader.java deleted file mode 100644 index 1d3e4cc672..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStoreUpgrader.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Map; -import java.util.UUID; - -public interface DurableConfigurationStoreUpgrader -{ - void configuredObject(UUID id, String type, Map<String, Object> attributes); - - void complete(); - - void setNextUpgrader(DurableConfigurationStoreUpgrader upgrader); - - Map<UUID, ConfiguredObjectRecord> getUpdatedRecords(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfiguredObjectRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfiguredObjectRecoverer.java deleted file mode 100644 index e065728bd3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfiguredObjectRecoverer.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Map; -import java.util.UUID; - -public interface DurableConfiguredObjectRecoverer -{ - public void load(final DurableConfigurationRecoverer durableConfigurationRecoverer, - final UUID id, - final Map<String, Object> attributes); - - public String getType(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/Event.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/Event.java deleted file mode 100644 index c681126c11..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/Event.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -public enum Event -{ - BEFORE_INIT, - AFTER_INIT, - - BEFORE_ACTIVATE, - AFTER_ACTIVATE, - - BEFORE_PASSIVATE, - AFTER_PASSIVATE, - - BEFORE_CLOSE, - AFTER_CLOSE, - - BEFORE_QUIESCE, - AFTER_QUIESCE, - BEFORE_RESTART, - - PERSISTENT_MESSAGE_SIZE_OVERFULL, - PERSISTENT_MESSAGE_SIZE_UNDERFULL -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/EventListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/EventListener.java deleted file mode 100644 index 33ae7b5b24..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/EventListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -public interface EventListener -{ - public void event(Event event); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/EventManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/EventManager.java deleted file mode 100644 index bf3de2611d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/EventManager.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; - -import org.apache.log4j.Logger; - -public class EventManager -{ - private Map<Event, List<EventListener>> _listeners = new EnumMap<Event, List<EventListener>> (Event.class); - private static final Logger _LOGGER = Logger.getLogger(EventManager.class); - - public synchronized void addEventListener(EventListener listener, Event... events) - { - for(Event event : events) - { - List<EventListener> list = _listeners.get(event); - if(list == null) - { - list = new ArrayList<EventListener>(); - _listeners.put(event,list); - } - list.add(listener); - } - } - - public synchronized void notifyEvent(Event event) - { - if (_listeners.containsKey(event)) - { - if(_LOGGER.isDebugEnabled()) - { - _LOGGER.debug("Received event " + event); - } - - for (EventListener listener : _listeners.get(event)) - { - listener.event(event); - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/HAMessageStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/HAMessageStore.java deleted file mode 100644 index 59483751ca..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/HAMessageStore.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -public interface HAMessageStore extends MessageStore -{ - /** - * Used to indicate that a store requires to make itself unavailable for read and read/write - * operations. - */ - void passivate(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java deleted file mode 100644 index 8eed1fa5a4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java +++ /dev/null @@ -1,513 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.channels.OverlappingFileLockException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.Model; -import org.apache.qpid.server.model.VirtualHost; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; - -public class JsonFileConfigStore implements DurableConfigurationStore -{ - private static final Model MODEL = Model.getInstance(); - - private static final Map<String,Class<? extends ConfiguredObject>> CLASS_NAME_MAPPING = generateClassNameMap(VirtualHost.class); - public static final String TYPE = "JSON"; - - private final Map<UUID, ConfiguredObjectRecord> _objectsById = new HashMap<UUID, ConfiguredObjectRecord>(); - private final Map<String, List<UUID>> _idsByType = new HashMap<String, List<UUID>>(); - private final ObjectMapper _objectMapper = new ObjectMapper(); - - private String _directoryName; - private String _name; - private FileLock _fileLock; - private String _configFileName; - private String _backupFileName; - private int _configVersion; - - public JsonFileConfigStore() - { - _objectMapper.enable(SerializationConfig.Feature.INDENT_OUTPUT); - } - - @Override - public void configureConfigStore(final VirtualHost virtualHost, final ConfigurationRecoveryHandler recoveryHandler) - throws Exception - { - _name = virtualHost.getName(); - - Object storePathAttr = virtualHost.getAttribute(VirtualHost.CONFIG_STORE_PATH); - if(!(storePathAttr instanceof String)) - { - throw new AMQStoreException("Cannot determine path for configuration storage"); - } - _directoryName = (String) storePathAttr; - _configFileName = _name + ".json"; - _backupFileName = _name + ".bak"; - checkDirectoryIsWritable(_directoryName); - getFileLock(); - - if(!fileExists(_configFileName)) - { - if(!fileExists(_backupFileName)) - { - File newFile = new File(_directoryName, _configFileName); - _objectMapper.writeValue(newFile, Collections.emptyMap()); - } - else - { - renameFile(_backupFileName, _configFileName); - } - } - - - load(); - recoveryHandler.beginConfigurationRecovery(this,_configVersion); - List<ConfiguredObjectRecord> records = new ArrayList<ConfiguredObjectRecord>(_objectsById.values()); - for(ConfiguredObjectRecord record : records) - { - recoveryHandler.configuredObject(record.getId(), record.getType(), record.getAttributes()); - } - int oldConfigVersion = _configVersion; - _configVersion = recoveryHandler.completeConfigurationRecovery(); - if(oldConfigVersion != _configVersion) - { - save(); - } - } - - private void renameFile(String fromFileName, String toFileName) throws AMQStoreException - { - File toFile = new File(_directoryName, toFileName); - if(toFile.exists()) - { - if(!toFile.delete()) - { - throw new AMQStoreException("Cannot delete file " + toFile.getAbsolutePath()); - } - } - File fromFile = new File(_directoryName, fromFileName); - - if(!fromFile.renameTo(toFile)) - { - throw new AMQStoreException("Cannot rename file " + fromFile.getAbsolutePath() + " to " + toFile.getAbsolutePath()); - } - } - - private boolean fileExists(String fileName) - { - File file = new File(_directoryName, fileName); - return file.exists(); - } - - private void getFileLock() throws IOException, AMQStoreException - { - File lockFile = new File(_directoryName, _name + ".lck"); - lockFile.createNewFile(); - - FileOutputStream out = new FileOutputStream(lockFile); - FileChannel channel = out.getChannel(); - try - { - _fileLock = channel.tryLock(); - } - catch(OverlappingFileLockException e) - { - _fileLock = null; - } - if(_fileLock == null) - { - throw new AMQStoreException("Cannot get lock on file " + lockFile.getAbsolutePath() + " is another instance running?"); - } - lockFile.deleteOnExit(); - } - - private void checkDirectoryIsWritable(String directoryName) throws AMQStoreException - { - File dir = new File(directoryName); - if(dir.exists()) - { - if(dir.isDirectory()) - { - if(!dir.canWrite()) - { - throw new AMQStoreException("Configuration path " + directoryName + " exists, but is not writable"); - } - - } - else - { - throw new AMQStoreException("Configuration path " + directoryName + " exists, but is not a directory"); - } - } - else if(!dir.mkdirs()) - { - throw new AMQStoreException("Cannot create directory " + directoryName); - } - } - - private void load() throws IOException - { - Map data = _objectMapper.readValue(new File(_directoryName,_configFileName),Map.class); - Collection<Class<? extends ConfiguredObject>> childClasses = - MODEL.getChildTypes(VirtualHost.class); - String modelVersion = (String) data.remove("modelVersion"); - Object configVersion; - if((configVersion = data.remove("configVersion")) instanceof Integer) - { - _configVersion = (Integer) configVersion; - } - for(Class<? extends ConfiguredObject> childClass : childClasses) - { - final String type = childClass.getSimpleName(); - String attrName = type.toLowerCase() + "s"; - Object children = data.remove(attrName); - if(children != null) - { - if(children instanceof Collection) - { - for(Object child : (Collection)children) - { - if(child instanceof Map) - { - loadChild(childClass, (Map)child, VirtualHost.class, null); - } - } - } - } - } - } - - private void loadChild(final Class<? extends ConfiguredObject> clazz, - final Map<String,Object> data, - final Class<? extends ConfiguredObject> parentClass, - final UUID parentId) - { - Collection<Class<? extends ConfiguredObject>> childClasses = - MODEL.getChildTypes(clazz); - String idStr = (String) data.remove("id"); - final UUID id = UUID.fromString(idStr); - final String type = clazz.getSimpleName(); - - for(Class<? extends ConfiguredObject> childClass : childClasses) - { - final String childType = childClass.getSimpleName(); - String attrName = childType.toLowerCase() + "s"; - Object children = data.remove(attrName); - if(children != null) - { - if(children instanceof Collection) - { - for(Object child : (Collection)children) - { - if(child instanceof Map) - { - loadChild(childClass, (Map)child, clazz, id); - } - } - } - } - - } - if(parentId != null) - { - data.put(parentClass.getSimpleName().toLowerCase(),parentId); - for(Class<? extends ConfiguredObject> otherParent : MODEL.getParentTypes(clazz)) - { - if(otherParent != parentClass) - { - final String otherParentAttr = otherParent.getSimpleName().toLowerCase(); - Object otherParentId = data.get(otherParentAttr); - if(otherParentId instanceof String) - { - try - { - data.put(otherParentAttr, UUID.fromString((String) otherParentId)); - } - catch(IllegalArgumentException e) - { - // - } - } - } - - } - } - - _objectsById.put(id, new ConfiguredObjectRecord(id, type, data)); - List<UUID> idsForType = _idsByType.get(type); - if(idsForType == null) - { - idsForType = new ArrayList<UUID>(); - _idsByType.put(type, idsForType); - } - idsForType.add(id); - - } - - @Override - public synchronized void create(final UUID id, final String type, final Map<String, Object> attributes) throws AMQStoreException - { - if(_objectsById.containsKey(id)) - { - throw new AMQStoreException("Object with id " + id + " already exists"); - } - else if(!CLASS_NAME_MAPPING.containsKey(type)) - { - throw new AMQStoreException("Cannot create object of unknown type " + type); - } - else - { - ConfiguredObjectRecord record = new ConfiguredObjectRecord(id, type, attributes); - _objectsById.put(id, record); - List<UUID> idsForType = _idsByType.get(type); - if(idsForType == null) - { - idsForType = new ArrayList<UUID>(); - _idsByType.put(type, idsForType); - } - idsForType.add(id); - save(); - } - } - - private void save() throws AMQStoreException - { - Collection<Class<? extends ConfiguredObject>> childClasses = - MODEL.getChildTypes(VirtualHost.class); - - Map<String, Object> virtualHostMap = new LinkedHashMap<String, Object>(); - virtualHostMap.put("modelVersion", Model.MODEL_VERSION); - virtualHostMap.put("configVersion", _configVersion); - - for(Class<? extends ConfiguredObject> childClass : childClasses) - { - final String type = childClass.getSimpleName(); - String attrName = type.toLowerCase() + "s"; - List<UUID> childIds = _idsByType.get(type); - if(childIds != null && !childIds.isEmpty()) - { - List<Map<String,Object>> entities = new ArrayList<Map<String, Object>>(); - for(UUID id : childIds) - { - entities.add(build(childClass,id)); - } - virtualHostMap.put(attrName, entities); - } - } - - try - { - - File tmpFile = File.createTempFile("cfg","tmp", new File(_directoryName)); - tmpFile.deleteOnExit(); - _objectMapper.writeValue(tmpFile,virtualHostMap); - renameFile(_configFileName,_backupFileName); - renameFile(tmpFile.getName(),_configFileName); - tmpFile.delete(); - File backupFile = new File(_directoryName, _backupFileName); - backupFile.delete(); - - } - catch (IOException e) - { - throw new AMQStoreException("Cannot save to store", e); - } - } - - private Map<String, Object> build(final Class<? extends ConfiguredObject> type, final UUID id) - { - ConfiguredObjectRecord record = _objectsById.get(id); - Map<String,Object> map = new LinkedHashMap<String, Object>(); - map.put("id", id); - map.putAll(record.getAttributes()); - map.remove(MODEL.getParentTypes(type).iterator().next().getSimpleName().toLowerCase()); - - Collection<Class<? extends ConfiguredObject>> childClasses = - new ArrayList<Class<? extends ConfiguredObject>>(MODEL.getChildTypes(type)); - - for(Class<? extends ConfiguredObject> childClass : childClasses) - { - // only add if this is the "first" parent - if(MODEL.getParentTypes(childClass).iterator().next() == type) - { - String attrName = childClass.getSimpleName().toLowerCase() + "s"; - List<UUID> childIds = _idsByType.get(childClass.getSimpleName()); - if(childIds != null) - { - List<Map<String,Object>> entities = new ArrayList<Map<String, Object>>(); - for(UUID childId : childIds) - { - ConfiguredObjectRecord childRecord = _objectsById.get(childId); - final String parentArg = type.getSimpleName().toLowerCase(); - if(id.toString().equals(String.valueOf(childRecord.getAttributes().get(parentArg)))) - { - entities.add(build(childClass,childId)); - } - } - if(!entities.isEmpty()) - { - map.put(attrName,entities); - } - } - } - } - - return map; - } - - @Override - public void remove(final UUID id, final String type) throws AMQStoreException - { - removeConfiguredObjects(id); - } - - @Override - public synchronized UUID[] removeConfiguredObjects(final UUID... objects) throws AMQStoreException - { - List<UUID> removedIds = new ArrayList<UUID>(); - for(UUID id : objects) - { - ConfiguredObjectRecord record = _objectsById.remove(id); - if(record != null) - { - removedIds.add(id); - _idsByType.get(record.getType()).remove(id); - } - } - save(); - return removedIds.toArray(new UUID[removedIds.size()]); - } - - @Override - public void update(final UUID id, final String type, final Map<String, Object> attributes) throws AMQStoreException - { - update(false, new ConfiguredObjectRecord(id, type, attributes)); - } - - @Override - public void update(final ConfiguredObjectRecord... records) throws AMQStoreException - { - update(false, records); - } - - @Override - public void update(final boolean createIfNecessary, final ConfiguredObjectRecord... records) - throws AMQStoreException - { - for(ConfiguredObjectRecord record : records) - { - final UUID id = record.getId(); - final String type = record.getType(); - - if(_objectsById.containsKey(id)) - { - final ConfiguredObjectRecord existingRecord = _objectsById.get(id); - if(!type.equals(existingRecord.getType())) - { - throw new AMQStoreException("Cannot change the type of record " + id + " from type " - + existingRecord.getType() + " to type " + type); - } - } - else if(!createIfNecessary) - { - throw new AMQStoreException("Cannot update record with id " + id - + " of type " + type + " as it does not exist"); - } - else if(!CLASS_NAME_MAPPING.containsKey(type)) - { - throw new AMQStoreException("Cannot update record of unknown type " + type); - } - } - for(ConfiguredObjectRecord record : records) - { - final UUID id = record.getId(); - final String type = record.getType(); - if(_objectsById.put(id, record) == null) - { - List<UUID> idsForType = _idsByType.get(type); - if(idsForType == null) - { - idsForType = new ArrayList<UUID>(); - _idsByType.put(type, idsForType); - } - idsForType.add(id); - } - } - - save(); - } - - public void close() throws Exception - { - try - { - releaseFileLock(); - } - finally - { - _fileLock = null; - _idsByType.clear(); - _objectsById.clear(); - } - - } - - private void releaseFileLock() throws IOException - { - _fileLock.release(); - _fileLock.channel().close(); - } - - - private static Map<String,Class<? extends ConfiguredObject>> generateClassNameMap(final Class<? extends ConfiguredObject> clazz) - { - Map<String,Class<? extends ConfiguredObject>>map = new HashMap<String, Class<? extends ConfiguredObject>>(); - map.put(clazz.getSimpleName().toString(), clazz); - Collection<Class<? extends ConfiguredObject>> childClasses = MODEL.getChildTypes(clazz); - if(childClasses != null) - { - for(Class<? extends ConfiguredObject> childClass : childClasses) - { - map.putAll(generateClassNameMap(childClass)); - } - } - return map; - } - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/JsonFileConfigStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/JsonFileConfigStoreFactory.java deleted file mode 100644 index 374a35d10d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/JsonFileConfigStoreFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Map; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.plugin.DurableConfigurationStoreFactory; - -public class JsonFileConfigStoreFactory implements DurableConfigurationStoreFactory -{ - @Override - public String getType() - { - return JsonFileConfigStore.TYPE; - } - - @Override - public DurableConfigurationStore createDurableConfigurationStore() - { - return new JsonFileConfigStore(); - } - - @Override - public void validateAttributes(Map<String, Object> attributes) - { - Object storePath = attributes.get(VirtualHost.CONFIG_STORE_PATH); - if(!(storePath instanceof String)) - { - throw new IllegalArgumentException("Attribute '"+ VirtualHost.CONFIG_STORE_PATH - +"' is required and must be of type String."); - - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageMetaDataTypeRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageMetaDataTypeRegistry.java deleted file mode 100644 index 64f3ab15ee..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageMetaDataTypeRegistry.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import org.apache.qpid.server.plugin.MessageMetaDataType; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class MessageMetaDataTypeRegistry -{ - private static MessageMetaDataType[] values; - - static - { - int maxOrdinal = -1; - - Iterable<MessageMetaDataType> messageMetaDataTypes = - new QpidServiceLoader<MessageMetaDataType>().atLeastOneInstanceOf(MessageMetaDataType.class); - - for(MessageMetaDataType type : messageMetaDataTypes) - { - if(type.ordinal()>maxOrdinal) - { - maxOrdinal = type.ordinal(); - } - } - values = new MessageMetaDataType[maxOrdinal+1]; - for(MessageMetaDataType type : new QpidServiceLoader<MessageMetaDataType>().instancesOf(MessageMetaDataType.class)) - { - if(values[type.ordinal()] != null) - { - throw new IllegalStateException("Multiple MessageDataType (" - +values[type.ordinal()].getClass().getName() - +", " - + type.getClass().getName() - + ") defined for the same ordinal value: " + type.ordinal()); - } - values[type.ordinal()] = type; - } - } - - - public static MessageMetaDataType fromOrdinal(int ordinal) - { - return values[ordinal]; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStore.java deleted file mode 100644 index 996d71d51d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStore.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import org.apache.qpid.server.model.VirtualHost; - -/** - * MessageStore defines the interface to a storage area, which can be used to preserve the state of messages. - * - */ -public interface MessageStore -{ - /** - * Called after instantiation in order to configure the message store. A particular implementation can define - * whatever parameters it wants. - * - * - * - * - * @param virtualHost - * @param messageRecoveryHandler Handler to be called as the store recovers on start up - * @param tlogRecoveryHandler - * @throws Exception If any error occurs that means the store is unable to configure itself. - */ - void configureMessageStore(VirtualHost virtualHost, MessageStoreRecoveryHandler messageRecoveryHandler, - TransactionLogRecoveryHandler tlogRecoveryHandler) throws Exception; - - void activate() throws Exception; - - public <T extends StorableMessageMetaData> StoredMessage<T> addMessage(T metaData); - - - /** - * Is this store capable of persisting the data - * - * @return true if this store is capable of persisting data - */ - boolean isPersistent(); - - Transaction newTransaction(); - - /** - * Called to close and cleanup any resources used by the message store. - * - * @throws Exception If the close fails. - */ - void close() throws Exception; - - void addEventListener(EventListener eventListener, Event... events); - - String getStoreLocation(); - - String getStoreType(); - - void onDelete(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreClosedException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreClosedException.java deleted file mode 100644 index b0a736c66c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreClosedException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import org.apache.qpid.AMQException; - -/** - * NOTE: this class currently extends AMQException but - * we should be using AMQExceptions internally in the code base for Protocol errors hence - * the message store interface should throw a different super class which this should be - * moved to reflect - */ -public class MessageStoreClosedException extends AMQException -{ - public MessageStoreClosedException() - { - super("Message store closed"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreConstants.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreConstants.java deleted file mode 100644 index 93b669e6e4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreConstants.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -public class MessageStoreConstants -{ - - public static final String ENVIRONMENT_PATH_PROPERTY = "environment-path"; - public static final String OVERFULL_SIZE_PROPERTY = "overfull-size"; - public static final String UNDERFULL_SIZE_PROPERTY = "underfull-size"; - public static final String OVERFULL_SIZE_ATTRIBUTE = "storeOverfullSize"; - public static final String UNDERFULL_SIZE_ATTRIBUTE = "storeUnderfullSize"; - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java deleted file mode 100644 index a8013b8e9b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.plugin.MessageStoreFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class MessageStoreCreator -{ - private Map<String, MessageStoreFactory> _factories = new HashMap<String, MessageStoreFactory>(); - - public MessageStoreCreator() - { - QpidServiceLoader<MessageStoreFactory> qpidServiceLoader = new QpidServiceLoader<MessageStoreFactory>(); - Iterable<MessageStoreFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(MessageStoreFactory.class); - for (MessageStoreFactory messageStoreFactory : factories) - { - String type = messageStoreFactory.getType(); - MessageStoreFactory factory = _factories.put(type.toLowerCase(), messageStoreFactory); - if (factory != null) - { - throw new IllegalStateException("MessageStoreFactory with type name '" + type - + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '" - + messageStoreFactory.getClass().getName() + "'"); - } - } - } - - public boolean isValidType(String storeType) - { - return _factories.containsKey(storeType.toLowerCase()); - } - - - public MessageStore createMessageStore(String storeType) - { - MessageStoreFactory factory = _factories.get(storeType.toLowerCase()); - if (factory == null) - { - throw new IllegalConfigurationException("Unknown store type: " + storeType - + ". Supported types: " + _factories.keySet()); - } - return factory.createMessageStore(); - } - - public Collection<MessageStoreFactory> getFactories() - { - return Collections.unmodifiableCollection(_factories.values()); - } - - public Collection<String> getStoreTypes() - { - return Collections.unmodifiableCollection(_factories.keySet()); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreRecoveryHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreRecoveryHandler.java deleted file mode 100755 index ba65b8e1ec..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreRecoveryHandler.java +++ /dev/null @@ -1,33 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.store; - -public interface MessageStoreRecoveryHandler -{ - StoredMessageRecoveryHandler begin(); - - public static interface StoredMessageRecoveryHandler - { - void message(StoredMessage message); - - void completeMessageRecovery(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NonNullUpgrader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NonNullUpgrader.java deleted file mode 100644 index a671e93b26..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NonNullUpgrader.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public abstract class NonNullUpgrader implements DurableConfigurationStoreUpgrader -{ - private DurableConfigurationStoreUpgrader _nextUpgrader; - private final Map<UUID, ConfiguredObjectRecord> _updates = new HashMap<UUID, ConfiguredObjectRecord>(); - - public final void setNextUpgrader(final DurableConfigurationStoreUpgrader upgrader) - { - if(_nextUpgrader == null) - { - _nextUpgrader = upgrader; - } - else - { - _nextUpgrader.setNextUpgrader(upgrader); - } - } - - protected DurableConfigurationStoreUpgrader getNextUpgrader() - { - return _nextUpgrader; - } - - protected Map<UUID, ConfiguredObjectRecord> getUpdateMap() - { - return _updates; - } - - @Override - public final Map<UUID, ConfiguredObjectRecord> getUpdatedRecords() - { - final Map<UUID, ConfiguredObjectRecord> updates = new HashMap<UUID, ConfiguredObjectRecord>(_updates); - updates.putAll(_nextUpgrader.getUpdatedRecords()); - return updates; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NullMessageStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NullMessageStore.java deleted file mode 100644 index 57dbfabaa4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NullMessageStore.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Map; -import java.util.UUID; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.model.VirtualHost; - -public abstract class NullMessageStore implements MessageStore, DurableConfigurationStore -{ - @Override - public void configureConfigStore(VirtualHost virtualHost, ConfigurationRecoveryHandler recoveryHandler) throws Exception - { - } - - @Override - public void update(UUID id, String type, Map<String, Object> attributes) - { - } - - @Override - public void update(ConfiguredObjectRecord... records) throws AMQStoreException - { - } - - @Override - public void update(boolean createIfNecessary, ConfiguredObjectRecord... records) throws AMQStoreException - { - } - - - @Override - public void remove(UUID id, String type) - { - } - - @Override - public UUID[] removeConfiguredObjects(final UUID... objects) throws AMQStoreException - { - return objects; - } - - @Override - public void create(UUID id, String type, Map<String, Object> attributes) - { - } - - @Override - public void configureMessageStore(VirtualHost virtualHost, MessageStoreRecoveryHandler recoveryHandler, - TransactionLogRecoveryHandler tlogRecoveryHandler) throws Exception - { - } - - @Override - public void close() throws Exception - { - } - - @Override - public <T extends StorableMessageMetaData> StoredMessage<T> addMessage(T metaData) - { - return null; - } - - @Override - public boolean isPersistent() - { - return false; - } - - @Override - public Transaction newTransaction() - { - return null; - } - - @Override - public void activate() throws Exception - { - } - - @Override - public void addEventListener(EventListener eventListener, Event... events) - { - } - - @Override - public String getStoreLocation() - { - return null; - } - - @Override - public void onDelete() - { - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NullUpgrader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NullUpgrader.java deleted file mode 100644 index c8a812fa89..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/NullUpgrader.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.Collections; -import java.util.Map; -import java.util.UUID; - -public final class NullUpgrader implements DurableConfigurationStoreUpgrader -{ - private DurableConfigurationRecoverer _durableConfigurationRecoverer; - - public NullUpgrader(final DurableConfigurationRecoverer durableConfigurationRecoverer) - { - _durableConfigurationRecoverer = durableConfigurationRecoverer; - } - - @Override - public void configuredObject(final UUID id, final String type, final Map<String, Object> attributes) - { - _durableConfigurationRecoverer.onConfiguredObject(id, type, attributes); - } - - @Override - public void complete() - { - } - - @Override - public void setNextUpgrader(final DurableConfigurationStoreUpgrader upgrader) - { - throw new UnsupportedOperationException("NullUpgrader must always be the last upgrader"); - } - - @Override - public Map<UUID, ConfiguredObjectRecord> getUpdatedRecords() - { - return Collections.emptyMap(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/OperationalLoggingListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/OperationalLoggingListener.java deleted file mode 100644 index 4ab1a3ab05..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/OperationalLoggingListener.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.ConfigStoreMessages; -import org.apache.qpid.server.logging.messages.MessageStoreMessages; -import org.apache.qpid.server.logging.messages.TransactionLogMessages; - -public class OperationalLoggingListener implements EventListener -{ - protected final LogSubject _logSubject; - private MessageStore _store; - - private OperationalLoggingListener(final MessageStore store, LogSubject logSubject) - { - _logSubject = logSubject; - store.addEventListener(this, - Event.BEFORE_INIT, - Event.AFTER_INIT, - Event.BEFORE_ACTIVATE, - Event.AFTER_ACTIVATE, - Event.AFTER_CLOSE, - Event.PERSISTENT_MESSAGE_SIZE_OVERFULL, - Event.PERSISTENT_MESSAGE_SIZE_UNDERFULL); - _store = store; - } - - public void event(Event event) - { - switch(event) - { - case BEFORE_INIT: - CurrentActor.get().message(_logSubject, ConfigStoreMessages.CREATED()); - break; - case AFTER_INIT: - CurrentActor.get().message(_logSubject, MessageStoreMessages.CREATED()); - CurrentActor.get().message(_logSubject, TransactionLogMessages.CREATED()); - String storeLocation = _store.getStoreLocation(); - if (storeLocation != null) - { - CurrentActor.get().message(_logSubject, MessageStoreMessages.STORE_LOCATION(storeLocation)); - } - break; - case BEFORE_ACTIVATE: - CurrentActor.get().message(_logSubject, MessageStoreMessages.RECOVERY_START()); - break; - case AFTER_ACTIVATE: - CurrentActor.get().message(_logSubject, MessageStoreMessages.RECOVERY_COMPLETE()); - break; - case AFTER_CLOSE: - CurrentActor.get().message(_logSubject,MessageStoreMessages.CLOSED()); - break; - case PERSISTENT_MESSAGE_SIZE_OVERFULL: - CurrentActor.get().message(_logSubject,MessageStoreMessages.OVERFULL()); - break; - case PERSISTENT_MESSAGE_SIZE_UNDERFULL: - CurrentActor.get().message(_logSubject,MessageStoreMessages.UNDERFULL()); - break; - - } - } - - public static void listen(final MessageStore store, LogSubject logSubject) - { - new OperationalLoggingListener(store, logSubject); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/State.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/State.java deleted file mode 100644 index 1d0936cec4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/State.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -public enum State -{ - /** The initial state of the store. In practice, the store immediately transitions to the subsequent states. */ - INITIAL, - - INITIALISING, - /** - * The initial set-up of the store has completed. - * If the store is persistent, it has not yet loaded configuration from disk. - * - * From the point of view of the user, the store is essentially stopped. - */ - INITIALISED, - - ACTIVATING, - ACTIVE, - - CLOSING, - CLOSED, - - QUIESCING, - /** The virtual host (and implicitly also the store) has been manually paused by the user to allow configuration changes to take place */ - QUIESCED; - -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StateManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StateManager.java deleted file mode 100644 index 613b329beb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StateManager.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - - -import java.util.EnumMap; -import java.util.Map; - -import org.apache.qpid.server.store.StateManager.Transition; - -public class StateManager -{ - private State _state = State.INITIAL; - private EventListener _eventListener; - - private static final Map<State,Map<State, Transition>> _validTransitions = new EnumMap<State, Map<State, Transition>>(State.class); - - - static class Transition - { - private final Event _event; - private final State _endState; - private final State _startState; - - public Transition(State startState, State endState, Event event) - { - _event = event; - _startState = startState; - _endState = endState; - - Map<State, Transition> stateTransitions = _validTransitions.get(startState); - if(stateTransitions == null) - { - stateTransitions = new EnumMap<State, Transition>(State.class); - _validTransitions.put(startState, stateTransitions); - } - stateTransitions.put(endState, this); - } - - public Event getEvent() - { - return _event; - } - - public State getStartState() - { - return _startState; - } - - public State getEndState() - { - return _endState; - } - - } - - public static final Transition INITIALISE = new Transition(State.INITIAL, State.INITIALISING, Event.BEFORE_INIT); - public static final Transition INITALISE_COMPLETE = new Transition(State.INITIALISING, State.INITIALISED, Event.AFTER_INIT); - - public static final Transition ACTIVATE = new Transition(State.INITIALISED, State.ACTIVATING, Event.BEFORE_ACTIVATE); - public static final Transition ACTIVATE_COMPLETE = new Transition(State.ACTIVATING, State.ACTIVE, Event.AFTER_ACTIVATE); - - public static final Transition CLOSE_INITIALISED = new Transition(State.INITIALISED, State.CLOSING, Event.BEFORE_CLOSE);; - public static final Transition CLOSE_ACTIVE = new Transition(State.ACTIVE, State.CLOSING, Event.BEFORE_CLOSE); - public static final Transition CLOSE_QUIESCED = new Transition(State.QUIESCED, State.CLOSING, Event.BEFORE_CLOSE); - public static final Transition CLOSE_COMPLETE = new Transition(State.CLOSING, State.CLOSED, Event.AFTER_CLOSE); - - public static final Transition PASSIVATE = new Transition(State.ACTIVE, State.INITIALISED, Event.BEFORE_PASSIVATE); - - public static final Transition QUIESCE = new Transition(State.ACTIVE, State.QUIESCING, Event.BEFORE_QUIESCE); - public static final Transition QUIESCE_COMPLETE = new Transition(State.QUIESCING, State.QUIESCED, Event.AFTER_QUIESCE); - - public static final Transition RESTART = new Transition(State.QUIESCED, State.ACTIVATING, Event.BEFORE_RESTART); - - - public StateManager(final EventManager eventManager) - { - this(new EventListener() - { - @Override - public void event(Event event) - { - eventManager.notifyEvent(event); - } - }); - } - - - public StateManager(EventListener eventListener) - { - _eventListener = eventListener; - } - - public synchronized State getState() - { - return _state; - } - - public synchronized void attainState(State desired) - { - Transition transition = null; - final Map<State, Transition> stateTransitionMap = _validTransitions.get(_state); - if(stateTransitionMap != null) - { - transition = stateTransitionMap.get(desired); - } - if(transition == null) - { - throw new IllegalStateException("No valid transition from state " + _state + " to state " + desired); - } - _state = desired; - _eventListener.event(transition.getEvent()); - } - - public synchronized boolean isInState(State testedState) - { - return _state.equals(testedState); - } - - public synchronized boolean isNotInState(State testedState) - { - return !isInState(testedState); - } - - public synchronized void checkInState(State checkedState) - { - if (isNotInState(checkedState)) - { - throw new IllegalStateException("Unexpected state. Was : " + _state + " but expected : " + checkedState); - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StorableMessageMetaData.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StorableMessageMetaData.java deleted file mode 100755 index 9ae6cca8e6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StorableMessageMetaData.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.nio.ByteBuffer; -import org.apache.qpid.server.plugin.MessageMetaDataType; - -public interface StorableMessageMetaData -{ - MessageMetaDataType getType(); - - int getStorableSize(); - - int writeToBuffer(int offsetInMetaData, ByteBuffer dest); - - int getContentSize(); - - boolean isPersistent(); -} - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoreContext.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoreContext.java deleted file mode 100644 index 88cc68bc71..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoreContext.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import org.apache.log4j.Logger; - -/** - * A context that the store can use to associate with a transactional context. For example, it could store - * some kind of txn id. - * - * @author Apache Software Foundation - */ -public class StoreContext -{ - private static final Logger _logger = Logger.getLogger(StoreContext.class); - - private String _name; - private Object _payload; - - - public StoreContext() - { - _name = "StoreContext"; - } - - public StoreContext(String name) - { - _name = name; - } - - public Object getPayload() - { - return _payload; - } - - public void setPayload(Object payload) - { - if(_logger.isDebugEnabled()) - { - _logger.debug("public void setPayload(Object payload = " + payload + "): called"); - } - _payload = payload; - } - - /** - * Prints out the transactional context as a string, mainly for debugging purposes. - * - * @return The transactional context as a string. - */ - public String toString() - { - return "<_name = " + _name + ", _payload = " + _payload + ">"; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoreFuture.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoreFuture.java deleted file mode 100644 index 7d3bf90a75..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoreFuture.java +++ /dev/null @@ -1,40 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.store; - -public interface StoreFuture -{ - StoreFuture IMMEDIATE_FUTURE = new StoreFuture() - { - public boolean isComplete() - { - return true; - } - - public void waitForCompletion() - { - } - }; - - boolean isComplete(); - - void waitForCompletion(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoredMemoryMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoredMemoryMessage.java deleted file mode 100755 index e7302270bb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoredMemoryMessage.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.nio.ByteBuffer; - -public class StoredMemoryMessage implements StoredMessage -{ - private final long _messageNumber; - private ByteBuffer _content; - private final StorableMessageMetaData _metaData; - - public StoredMemoryMessage(long messageNumber, StorableMessageMetaData metaData) - { - _messageNumber = messageNumber; - _metaData = metaData; - } - - public long getMessageNumber() - { - return _messageNumber; - } - - public void addContent(int offsetInMessage, ByteBuffer src) - { - if(_content == null) - { - if(offsetInMessage == 0) - { - _content = src.slice(); - } - else - { - final int contentSize = _metaData.getContentSize(); - int size = (contentSize < offsetInMessage + src.remaining()) - ? offsetInMessage + src.remaining() - : contentSize; - _content = ByteBuffer.allocate(size); - addContent(offsetInMessage, src); - } - } - else - { - if(_content.limit() >= offsetInMessage + src.remaining()) - { - _content.position(offsetInMessage); - _content.put(src); - _content.position(0); - } - else - { - final int contentSize = _metaData.getContentSize(); - int size = (contentSize < offsetInMessage + src.remaining()) - ? offsetInMessage + src.remaining() - : contentSize; - ByteBuffer oldContent = _content; - _content = ByteBuffer.allocate(size); - _content.put(oldContent); - _content.position(0); - addContent(offsetInMessage, src); - } - - } - } - - public int getContent(int offset, ByteBuffer dst) - { - if(_content == null) - { - return 0; - } - ByteBuffer src = _content.duplicate(); - - int oldPosition = src.position(); - - src.position(oldPosition + offset); - - int length = dst.remaining() < src.remaining() ? dst.remaining() : src.remaining(); - src.limit(oldPosition + length); - - dst.put(src); - - - return length; - } - - - public ByteBuffer getContent(int offsetInMessage, int size) - { - if(_content == null) - { - return null; - } - ByteBuffer buf = _content.duplicate(); - - if(offsetInMessage != 0) - { - buf.position(offsetInMessage); - buf = buf.slice(); - } - - buf.limit(size); - return buf; - } - - public StoreFuture flushToStore() - { - return StoreFuture.IMMEDIATE_FUTURE; - } - - - public StorableMessageMetaData getMetaData() - { - return _metaData; - } - - public void remove() - { - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoredMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoredMessage.java deleted file mode 100755 index 7909003855..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/StoredMessage.java +++ /dev/null @@ -1,40 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.store; - -import java.nio.ByteBuffer; - -public interface StoredMessage<M extends StorableMessageMetaData> -{ - M getMetaData(); - - public long getMessageNumber(); - - void addContent(int offsetInMessage, ByteBuffer src); - - int getContent(int offsetInMessage, ByteBuffer dst); - - ByteBuffer getContent(int offsetInMessage, int size); - - StoreFuture flushToStore(); - - void remove(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/Transaction.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/Transaction.java deleted file mode 100644 index ed6b89e373..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/Transaction.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.message.EnqueableMessage; - -public interface Transaction -{ - /** - * Places a message onto a specified queue, in a given transactional context. - * - * - * - * @param queue The queue to place the message on. - * @param message - * @throws org.apache.qpid.AMQStoreException If the operation fails for any reason. - */ - void enqueueMessage(TransactionLogResource queue, EnqueableMessage message) throws AMQStoreException; - - /** - * Extracts a message from a specified queue, in a given transactional context. - * - * @param queue The queue to place the message on. - * @param message The message to dequeue. - * @throws AMQStoreException If the operation fails for any reason, or if the specified message does not exist. - */ - void dequeueMessage(TransactionLogResource queue, EnqueableMessage message) throws AMQStoreException; - - - /** - * Commits all operations performed within a given transactional context. - * - * @throws AMQStoreException If the operation fails for any reason. - */ - void commitTran() throws AMQStoreException; - - /** - * Commits all operations performed within a given transactional context. - * - * @throws AMQStoreException If the operation fails for any reason. - */ - StoreFuture commitTranAsync() throws AMQStoreException; - - /** - * Abandons all operations performed within a given transactional context. - * - * @throws AMQStoreException If the operation fails for any reason. - */ - void abortTran() throws AMQStoreException; - - - public static interface Record - { - TransactionLogResource getQueue(); - EnqueableMessage getMessage(); - } - - void removeXid(long format, byte[] globalId, byte[] branchId) throws AMQStoreException; - - void recordXid(long format, byte[] globalId, byte[] branchId, Transaction.Record[] enqueues, Transaction.Record[] dequeues) - throws AMQStoreException; -}
\ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLog.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLog.java deleted file mode 100755 index da7f8d18b2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLog.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -public interface TransactionLog -{ - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLogRecoveryHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLogRecoveryHandler.java deleted file mode 100755 index bd4da648f9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLogRecoveryHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.store; - -import java.util.UUID; - -public interface TransactionLogRecoveryHandler -{ - QueueEntryRecoveryHandler begin(MessageStore log); - - public static interface QueueEntryRecoveryHandler - { - DtxRecordRecoveryHandler completeQueueEntryRecovery(); - - void queueEntry(UUID queueId, long messageId); - } - - public static interface DtxRecordRecoveryHandler - { - void dtxRecord(long format, byte[] globalId, byte[] branchId, Transaction.Record[] enqueues, Transaction.Record[] dequeues); - - void completeDtxRecordRecovery(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLogResource.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLogResource.java deleted file mode 100755 index 576dca847d..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/TransactionLogResource.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.store; - -import java.util.UUID; - -public interface TransactionLogResource -{ - public UUID getId(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UnresolvedDependency.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UnresolvedDependency.java deleted file mode 100644 index 98348efbd2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UnresolvedDependency.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -import java.util.UUID; - -public interface UnresolvedDependency<T> -{ - public UUID getId(); - public String getType(); - - public void resolve(final T dependency); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UnresolvedObject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UnresolvedObject.java deleted file mode 100644 index 7ebebadae7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UnresolvedObject.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -public interface UnresolvedObject<T> -{ - public UnresolvedDependency[] getUnresolvedDependencies(); - - T resolve(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UpgraderProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UpgraderProvider.java deleted file mode 100644 index c2ea0745ff..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/UpgraderProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store; - -public interface UpgraderProvider -{ - DurableConfigurationStoreUpgrader getUpgrader(int configVersion, DurableConfigurationRecoverer recoverer); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/jdbc/ConnectionProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/jdbc/ConnectionProvider.java deleted file mode 100644 index 54978776e7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/jdbc/ConnectionProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.store.jdbc; - -import java.sql.Connection; -import java.sql.SQLException; - -public interface ConnectionProvider -{ - Connection getConnection() throws SQLException; - - void close() throws SQLException; -} - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/AssignedSubscriptionMessageGroupManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/AssignedSubscriptionMessageGroupManager.java deleted file mode 100644 index efedad1181..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/AssignedSubscriptionMessageGroupManager.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.subscription; - -import org.apache.qpid.server.queue.QueueEntryVisitor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.server.queue.QueueEntry; - -import java.util.Iterator; -import java.util.concurrent.ConcurrentHashMap; - - -public class AssignedSubscriptionMessageGroupManager implements MessageGroupManager -{ - private static final Logger _logger = LoggerFactory.getLogger(AssignedSubscriptionMessageGroupManager.class); - - - private final String _groupId; - private final ConcurrentHashMap<Integer, Subscription> _groupMap = new ConcurrentHashMap<Integer, Subscription>(); - private final int _groupMask; - - public AssignedSubscriptionMessageGroupManager(final String groupId, final int maxGroups) - { - _groupId = groupId; - _groupMask = pow2(maxGroups)-1; - } - - private static int pow2(final int i) - { - int val = 1; - while(val < i) - { - val<<=1; - } - return val; - } - - public Subscription getAssignedSubscription(final QueueEntry entry) - { - Object groupVal = entry.getMessage().getMessageHeader().getHeader(_groupId); - return groupVal == null ? null : _groupMap.get(groupVal.hashCode() & _groupMask); - } - - public boolean acceptMessage(Subscription sub, QueueEntry entry) - { - Object groupVal = entry.getMessage().getMessageHeader().getHeader(_groupId); - if(groupVal == null) - { - return true; - } - else - { - Integer group = groupVal.hashCode() & _groupMask; - Subscription assignedSub = _groupMap.get(group); - if(assignedSub == sub) - { - return true; - } - else - { - if(assignedSub == null) - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Assigning group " + groupVal + " to sub " + sub); - } - assignedSub = _groupMap.putIfAbsent(group, sub); - return assignedSub == null || assignedSub == sub; - } - else - { - return false; - } - } - } - } - - public QueueEntry findEarliestAssignedAvailableEntry(Subscription sub) - { - EntryFinder visitor = new EntryFinder(sub); - sub.getQueue().visit(visitor); - return visitor.getEntry(); - } - - private class EntryFinder implements QueueEntryVisitor - { - private QueueEntry _entry; - private Subscription _sub; - - public EntryFinder(final Subscription sub) - { - _sub = sub; - } - - public boolean visit(final QueueEntry entry) - { - if(!entry.isAvailable()) - { - return false; - } - - Object groupId = entry.getMessage().getMessageHeader().getHeader(_groupId); - if(groupId == null) - { - return false; - } - - Integer group = groupId.hashCode() & _groupMask; - Subscription assignedSub = _groupMap.get(group); - if(assignedSub == _sub) - { - _entry = entry; - return true; - } - else - { - return false; - } - } - - public QueueEntry getEntry() - { - return _entry; - } - } - - public void clearAssignments(Subscription sub) - { - Iterator<Subscription> subIter = _groupMap.values().iterator(); - while(subIter.hasNext()) - { - if(subIter.next() == sub) - { - subIter.remove(); - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/ClientDeliveryMethod.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/ClientDeliveryMethod.java deleted file mode 100644 index 632b59d3fa..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/ClientDeliveryMethod.java +++ /dev/null @@ -1,29 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.subscription; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.queue.QueueEntry; - -public interface ClientDeliveryMethod -{ - void deliverToClient(final Subscription sub, final QueueEntry entry, final long deliveryTag) throws AMQException; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/DefinedGroupMessageGroupManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/DefinedGroupMessageGroupManager.java deleted file mode 100644 index f38e23b342..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/DefinedGroupMessageGroupManager.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.subscription; - -import org.apache.qpid.server.queue.QueueEntryVisitor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.server.message.AMQMessageHeader; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.queue.QueueEntry; - -import java.util.HashMap; -import java.util.Map; - -public class DefinedGroupMessageGroupManager implements MessageGroupManager -{ - private static final Logger _logger = LoggerFactory.getLogger(DefinedGroupMessageGroupManager.class); - - private final String _groupId; - private final String _defaultGroup; - private final Map<Object, Group> _groupMap = new HashMap<Object, Group>(); - private final SubscriptionResetHelper _resetHelper; - - private final class Group - { - private final Object _group; - private Subscription _subscription; - private int _activeCount; - - private Group(final Object key, final Subscription subscription) - { - _group = key; - _subscription = subscription; - } - - public boolean add() - { - if(_subscription != null) - { - _activeCount++; - return true; - } - else - { - return false; - } - } - - public void subtract() - { - if(--_activeCount == 0) - { - _resetHelper.resetSubPointersForGroups(_subscription, false); - _subscription = null; - _groupMap.remove(_group); - } - } - - @Override - public boolean equals(final Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - - Group group = (Group) o; - - return _group.equals(group._group); - } - - @Override - public int hashCode() - { - return _group.hashCode(); - } - - public boolean isValid() - { - return !(_subscription == null || (_activeCount == 0 && _subscription.isClosed())); - } - - public Subscription getSubscription() - { - return _subscription; - } - - @Override - public String toString() - { - return "Group{" + - "_group=" + _group + - ", _subscription=" + _subscription + - ", _activeCount=" + _activeCount + - '}'; - } - } - - public DefinedGroupMessageGroupManager(final String groupId, String defaultGroup, SubscriptionResetHelper resetHelper) - { - _groupId = groupId; - _defaultGroup = defaultGroup; - _resetHelper = resetHelper; - } - - public synchronized Subscription getAssignedSubscription(final QueueEntry entry) - { - Object groupId = getKey(entry); - - Group group = _groupMap.get(groupId); - return group == null || !group.isValid() ? null : group.getSubscription(); - } - - public synchronized boolean acceptMessage(final Subscription sub, final QueueEntry entry) - { - Object groupId = getKey(entry); - Group group = _groupMap.get(groupId); - - if(group == null || !group.isValid()) - { - group = new Group(groupId, sub); - - _groupMap.put(groupId, group); - - // there's a small change that the group became empty between the point at which getNextAvailable() was - // called on the subscription, and when accept message is called... in that case we want to avoid delivering - // out of order - if(_resetHelper.isEntryAheadOfSubscription(entry, sub)) - { - return false; - } - - } - - Subscription assignedSub = group.getSubscription(); - - if(assignedSub == sub) - { - entry.addStateChangeListener(new GroupStateChangeListener(group, entry)); - return true; - } - else - { - return false; - } - } - - - public synchronized QueueEntry findEarliestAssignedAvailableEntry(final Subscription sub) - { - EntryFinder visitor = new EntryFinder(sub); - sub.getQueue().visit(visitor); - return visitor.getEntry(); - } - - private class EntryFinder implements QueueEntryVisitor - { - private QueueEntry _entry; - private Subscription _sub; - - public EntryFinder(final Subscription sub) - { - _sub = sub; - } - - public boolean visit(final QueueEntry entry) - { - if(!entry.isAvailable()) - { - return false; - } - - Object groupId = getKey(entry); - - Group group = _groupMap.get(groupId); - if(group != null && group.getSubscription() == _sub) - { - _entry = entry; - return true; - } - else - { - return false; - } - } - - public QueueEntry getEntry() - { - return _entry; - } - } - - - public void clearAssignments(final Subscription sub) - { - } - - private Object getKey(QueueEntry entry) - { - ServerMessage message = entry.getMessage(); - AMQMessageHeader messageHeader = message == null ? null : message.getMessageHeader(); - Object groupVal = messageHeader == null ? _defaultGroup : messageHeader.getHeader(_groupId); - if(groupVal == null) - { - groupVal = _defaultGroup; - } - return groupVal; - } - - private class GroupStateChangeListener implements QueueEntry.StateChangeListener - { - private final Group _group; - - public GroupStateChangeListener(final Group group, - final QueueEntry entry) - { - _group = group; - } - - public void stateChanged(final QueueEntry entry, - final QueueEntry.State oldState, - final QueueEntry.State newState) - { - synchronized (DefinedGroupMessageGroupManager.this) - { - if(_group.isValid()) - { - if(oldState != newState) - { - if(newState == QueueEntry.State.ACQUIRED) - { - _group.add(); - } - else if(oldState == QueueEntry.State.ACQUIRED) - { - _group.subtract(); - } - } - } - else - { - entry.removeStateChangeListener(this); - } - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/MessageGroupManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/MessageGroupManager.java deleted file mode 100644 index 8ce4ce3344..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/MessageGroupManager.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.subscription; - -import org.apache.qpid.server.queue.QueueEntry; - -public interface MessageGroupManager -{ - public interface SubscriptionResetHelper - { - public void resetSubPointersForGroups(Subscription subscription, boolean clearAssignments); - - boolean isEntryAheadOfSubscription(QueueEntry entry, Subscription sub); - } - - Subscription getAssignedSubscription(QueueEntry entry); - - boolean acceptMessage(Subscription sub, QueueEntry entry); - - QueueEntry findEarliestAssignedAvailableEntry(Subscription sub); - - void clearAssignments(Subscription sub); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/RecordDeliveryMethod.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/RecordDeliveryMethod.java deleted file mode 100644 index e2ed4104de..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/RecordDeliveryMethod.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.subscription; - -import org.apache.qpid.server.queue.QueueEntry; - -public interface RecordDeliveryMethod -{ - void recordMessageDelivery(final Subscription sub, final QueueEntry entry, final long deliveryTag); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription.java deleted file mode 100644 index 36d49d8279..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.subscription; - -import java.util.concurrent.atomic.AtomicLong; -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.logging.LogActor; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.QueueEntry; - -public interface Subscription -{ - AtomicLong SUB_ID_GENERATOR = new AtomicLong(0); - - LogActor getLogActor(); - - boolean isTransient(); - - long getBytesOut(); - - long getMessagesOut(); - - long getUnacknowledgedBytes(); - - long getUnacknowledgedMessages(); - - public static enum State - { - ACTIVE, - SUSPENDED, - CLOSED - } - - public static interface StateListener - { - public void stateChange(Subscription sub, State oldState, State newState); - } - - AMQQueue getQueue(); - AMQSessionModel getSessionModel(); - - QueueEntry.SubscriptionAcquiredState getOwningState(); - - void setQueue(AMQQueue queue, boolean exclusive); - - void setNoLocal(boolean noLocal); - - long getSubscriptionID(); - - boolean isSuspended(); - - boolean hasInterest(QueueEntry msg); - - boolean isClosed(); - - boolean acquires(); - - boolean seesRequeues(); - - void close(); - - void send(QueueEntry entry, boolean batch) throws AMQException; - - void flushBatched(); - - void queueDeleted(AMQQueue queue); - - - boolean wouldSuspend(QueueEntry msg); - - boolean trySendLock(); - - - void getSendLock(); - - void releaseSendLock(); - - void releaseQueueEntry(final QueueEntry queueEntryImpl); - - void onDequeue(final QueueEntry queueEntry); - - void restoreCredit(final QueueEntry queueEntry); - - void setStateListener(final StateListener listener); - - public State getState(); - - AMQQueue.Context getQueueContext(); - - void setQueueContext(AMQQueue.Context queueContext); - - - boolean isActive(); - - public void set(String key, Object value); - - public Object get(String key); - - boolean isSessionTransactional(); - - void queueEmpty() throws AMQException; - - String getConsumerName(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionList.java deleted file mode 100644 index bf5ce31bd9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionList.java +++ /dev/null @@ -1,280 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.subscription; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -public class SubscriptionList -{ - private final SubscriptionNode _head = new SubscriptionNode(); - - private final AtomicReference<SubscriptionNode> _tail = new AtomicReference<SubscriptionNode>(_head); - private final AtomicReference<SubscriptionNode> _subNodeMarker = new AtomicReference<SubscriptionNode>(_head); - private final AtomicInteger _size = new AtomicInteger(); - - public static final class SubscriptionNode - { - private final AtomicBoolean _deleted = new AtomicBoolean(); - private final AtomicReference<SubscriptionNode> _next = new AtomicReference<SubscriptionNode>(); - private final Subscription _sub; - - public SubscriptionNode() - { - //used for sentinel head and dummy node construction - _sub = null; - _deleted.set(true); - } - - public SubscriptionNode(final Subscription sub) - { - //used for regular node construction - _sub = sub; - } - - /** - * Retrieves the first non-deleted node following the current node. - * Any deleted non-tail nodes encountered during the search are unlinked. - * - * @return the next non-deleted node, or null if none was found. - */ - public SubscriptionNode findNext() - { - SubscriptionNode next = nextNode(); - while(next != null && next.isDeleted()) - { - final SubscriptionNode newNext = next.nextNode(); - if(newNext != null) - { - //try to move our _next reference forward to the 'newNext' - //node to unlink the deleted node - _next.compareAndSet(next, newNext); - next = nextNode(); - } - else - { - //'newNext' is null, meaning 'next' is the current tail. Can't unlink - //the tail node for thread safety reasons, just use the null. - next = null; - } - } - - return next; - } - - /** - * Gets the immediately next referenced node in the structure. - * - * @return the immediately next node in the structure, or null if at the tail. - */ - protected SubscriptionNode nextNode() - { - return _next.get(); - } - - /** - * Used to initialise the 'next' reference. Will only succeed if the reference was not previously set. - * - * @param node the SubscriptionNode to set as 'next' - * @return whether the operation succeeded - */ - private boolean setNext(final SubscriptionNode node) - { - return _next.compareAndSet(null, node); - } - - public boolean isDeleted() - { - return _deleted.get(); - } - - public boolean delete() - { - return _deleted.compareAndSet(false,true); - } - - public Subscription getSubscription() - { - return _sub; - } - } - - private void insert(final SubscriptionNode node, final boolean count) - { - for (;;) - { - SubscriptionNode tail = _tail.get(); - SubscriptionNode next = tail.nextNode(); - if (tail == _tail.get()) - { - if (next == null) - { - if (tail.setNext(node)) - { - _tail.compareAndSet(tail, node); - if(count) - { - _size.incrementAndGet(); - } - return; - } - } - else - { - _tail.compareAndSet(tail, next); - } - } - } - } - - public void add(final Subscription sub) - { - SubscriptionNode node = new SubscriptionNode(sub); - insert(node, true); - } - - public boolean remove(final Subscription sub) - { - SubscriptionNode prevNode = _head; - SubscriptionNode node = _head.nextNode(); - - while(node != null) - { - if(sub.equals(node.getSubscription()) && node.delete()) - { - _size.decrementAndGet(); - - SubscriptionNode tail = _tail.get(); - if(node == tail) - { - //we cant remove the last node from the structure for - //correctness reasons, however we have just 'deleted' - //the tail. Inserting an empty dummy node after it will - //let us scavenge the node containing the Subscription. - insert(new SubscriptionNode(), false); - } - - //advance the next node reference in the 'prevNode' to scavange - //the newly 'deleted' node for the Subscription. - prevNode.findNext(); - - nodeMarkerCleanup(node); - - return true; - } - - prevNode = node; - node = node.findNext(); - } - - return false; - } - - private void nodeMarkerCleanup(final SubscriptionNode node) - { - SubscriptionNode markedNode = _subNodeMarker.get(); - if(node == markedNode) - { - //if the marked node is the one we are removing, then - //replace it with a dummy pointing at the next node. - //this is OK as the marked node is only used to index - //into the list and find the next node to use. - //Because we inserted a dummy if node was the - //tail, markedNode.nextNode() can never be null. - SubscriptionNode dummy = new SubscriptionNode(); - dummy.setNext(markedNode.nextNode()); - - //if the CAS fails the marked node has changed, thus - //we don't care about the dummy and just forget it - _subNodeMarker.compareAndSet(markedNode, dummy); - } - else if(markedNode != null) - { - //if the marked node was already deleted then it could - //hold subsequently removed nodes after it in the list - //in memory. Scavenge it to ensure their actual removal. - if(markedNode != _head && markedNode.isDeleted()) - { - markedNode.findNext(); - } - } - } - - public boolean updateMarkedNode(final SubscriptionNode expected, final SubscriptionNode nextNode) - { - return _subNodeMarker.compareAndSet(expected, nextNode); - } - - /** - * Get the current marked SubscriptionNode. This should only be used only to index into the list and find the next node - * after the mark, since if the previously marked node was subsequently deleted the item returned may be a dummy node - * with reference to the next node. - * - * @return the previously marked node (or a dummy if it was subsequently deleted) - */ - public SubscriptionNode getMarkedNode() - { - return _subNodeMarker.get(); - } - - - public static class SubscriptionNodeIterator - { - private SubscriptionNode _lastNode; - - SubscriptionNodeIterator(SubscriptionNode startNode) - { - _lastNode = startNode; - } - - public SubscriptionNode getNode() - { - return _lastNode; - } - - public boolean advance() - { - SubscriptionNode nextNode = _lastNode.findNext(); - _lastNode = nextNode; - - return _lastNode != null; - } - } - - public SubscriptionNodeIterator iterator() - { - return new SubscriptionNodeIterator(_head); - } - - public SubscriptionNode getHead() - { - return _head; - } - - public int size() - { - return _size.get(); - } -} - - - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AlreadyKnownDtxException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AlreadyKnownDtxException.java deleted file mode 100644 index faa4ec592f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AlreadyKnownDtxException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.transport.Xid; - -public class AlreadyKnownDtxException extends DtxException -{ - public AlreadyKnownDtxException(Xid id) - { - super("Xid " + id + " cannot be started as it is already known"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AsyncAutoCommitTransaction.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AsyncAutoCommitTransaction.java deleted file mode 100755 index 31e4dc6def..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AsyncAutoCommitTransaction.java +++ /dev/null @@ -1,360 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.queue.QueueEntry; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.StoreFuture; -import org.apache.qpid.server.store.Transaction; - -import java.util.Collection; -import java.util.List; - -/** - * An implementation of ServerTransaction where each enqueue/dequeue - * operation takes place within it own transaction. - * - * Since there is no long-lived transaction, the commit and rollback methods of - * this implementation are empty. - */ -public class AsyncAutoCommitTransaction implements ServerTransaction -{ - static final String QPID_STRICT_ORDER_WITH_MIXED_DELIVERY_MODE = "qpid.strict_order_with_mixed_delivery_mode"; - - protected static final Logger _logger = Logger.getLogger(AsyncAutoCommitTransaction.class); - - private final MessageStore _messageStore; - private final FutureRecorder _futureRecorder; - - //Set true to ensure strict ordering when enqueing messages with mixed delivery mode, i.e. disable async persistence - private boolean _strictOrderWithMixedDeliveryMode = Boolean.getBoolean(QPID_STRICT_ORDER_WITH_MIXED_DELIVERY_MODE); - - public static interface FutureRecorder - { - public void recordFuture(StoreFuture future, Action action); - - } - - public AsyncAutoCommitTransaction(MessageStore transactionLog, FutureRecorder recorder) - { - _messageStore = transactionLog; - _futureRecorder = recorder; - } - - @Override - public long getTransactionStartTime() - { - return 0L; - } - - @Override - public long getTransactionUpdateTime() - { - return 0L; - } - - /** - * Since AutoCommitTransaction have no concept of a long lived transaction, any Actions registered - * by the caller are executed immediately. - */ - public void addPostTransactionAction(final Action immediateAction) - { - addFuture(StoreFuture.IMMEDIATE_FUTURE, immediateAction); - - } - - public void dequeue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction) - { - Transaction txn = null; - try - { - StoreFuture future; - if(message.isPersistent() && queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Dequeue of message number " + message.getMessageNumber() + " from transaction log. Queue : " + queue.getName()); - } - - txn = _messageStore.newTransaction(); - txn.dequeueMessage(queue, message); - future = txn.commitTranAsync(); - - txn = null; - } - else - { - future = StoreFuture.IMMEDIATE_FUTURE; - } - addFuture(future, postTransactionAction); - postTransactionAction = null; - } - catch (AMQException e) - { - _logger.error("Error during message dequeue", e); - throw new RuntimeException("Error during message dequeue", e); - } - finally - { - rollbackIfNecessary(postTransactionAction, txn); - } - - } - - private void addFuture(final StoreFuture future, final Action action) - { - if(action != null) - { - if(future.isComplete()) - { - action.postCommit(); - } - else - { - _futureRecorder.recordFuture(future, action); - } - } - } - - private void addEnqueueFuture(final StoreFuture future, final Action action, boolean persistent) - { - if(action != null) - { - // For persistent messages, do not synchronously invoke postCommit even if the future is completed. - // Otherwise, postCommit (which actually does the enqueuing) might be called on successive messages out of order. - if(future.isComplete() && !persistent && !_strictOrderWithMixedDeliveryMode) - { - action.postCommit(); - } - else - { - _futureRecorder.recordFuture(future, action); - } - } - } - - public void dequeue(Collection<QueueEntry> queueEntries, Action postTransactionAction) - { - Transaction txn = null; - try - { - for(QueueEntry entry : queueEntries) - { - ServerMessage message = entry.getMessage(); - BaseQueue queue = entry.getQueue(); - - if(message.isPersistent() && queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Dequeue of message number " + message.getMessageNumber() + " from transaction log. Queue : " + queue.getName()); - } - - if(txn == null) - { - txn = _messageStore.newTransaction(); - } - - txn.dequeueMessage(queue, message); - } - - } - StoreFuture future; - if(txn != null) - { - future = txn.commitTranAsync(); - txn = null; - } - else - { - future = StoreFuture.IMMEDIATE_FUTURE; - } - addFuture(future, postTransactionAction); - postTransactionAction = null; - } - catch (AMQException e) - { - _logger.error("Error during message dequeues", e); - throw new RuntimeException("Error during message dequeues", e); - } - finally - { - rollbackIfNecessary(postTransactionAction, txn); - } - - } - - - public void enqueue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction) - { - Transaction txn = null; - try - { - StoreFuture future; - if(message.isPersistent() && queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getName()); - } - - txn = _messageStore.newTransaction(); - txn.enqueueMessage(queue, message); - future = txn.commitTranAsync(); - txn = null; - } - else - { - future = StoreFuture.IMMEDIATE_FUTURE; - } - addEnqueueFuture(future, postTransactionAction, message.isPersistent()); - postTransactionAction = null; - } - catch (AMQException e) - { - _logger.error("Error during message enqueue", e); - throw new RuntimeException("Error during message enqueue", e); - } - finally - { - rollbackIfNecessary(postTransactionAction, txn); - } - - - } - - public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction) - { - Transaction txn = null; - try - { - - if(message.isPersistent()) - { - for(BaseQueue queue : queues) - { - if (queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getName()); - } - if (txn == null) - { - txn = _messageStore.newTransaction(); - } - - txn.enqueueMessage(queue, message); - - - } - } - - } - StoreFuture future; - if (txn != null) - { - future = txn.commitTranAsync(); - txn = null; - } - else - { - future = StoreFuture.IMMEDIATE_FUTURE; - } - addEnqueueFuture(future, postTransactionAction, message.isPersistent()); - postTransactionAction = null; - - - } - catch (AMQException e) - { - _logger.error("Error during message enqueues", e); - throw new RuntimeException("Error during message enqueues", e); - } - finally - { - rollbackIfNecessary(postTransactionAction, txn); - } - - } - - - public void commit(final Runnable immediatePostTransactionAction) - { - if(immediatePostTransactionAction != null) - { - addFuture(StoreFuture.IMMEDIATE_FUTURE, new Action() - { - public void postCommit() - { - immediatePostTransactionAction.run(); - } - - public void onRollback() - { - } - }); - } - } - - public void commit() - { - } - - public void rollback() - { - } - - public boolean isTransactional() - { - return false; - } - - private void rollbackIfNecessary(Action postTransactionAction, Transaction txn) - { - if (txn != null) - { - try - { - txn.abortTran(); - } - catch (AMQStoreException e) - { - _logger.error("Abort transaction failed", e); - // Deliberate decision not to re-throw this exception. Rationale: we can only reach here if a previous - // TransactionLog method has ended in Exception. If we were to re-throw here, we would prevent - // our caller from receiving the original exception (which is likely to be more revealing of the underlying error). - } - } - if (postTransactionAction != null) - { - postTransactionAction.onRollback(); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AutoCommitTransaction.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AutoCommitTransaction.java deleted file mode 100755 index b081641f47..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/AutoCommitTransaction.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.queue.QueueEntry; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.Transaction; - -import java.util.Collection; -import java.util.List; - -/** - * An implementation of ServerTransaction where each enqueue/dequeue - * operation takes place within it own transaction. - * - * Since there is no long-lived transaction, the commit and rollback methods of - * this implementation are empty. - */ -public class AutoCommitTransaction implements ServerTransaction -{ - protected static final Logger _logger = Logger.getLogger(AutoCommitTransaction.class); - - private final MessageStore _messageStore; - - public AutoCommitTransaction(MessageStore transactionLog) - { - _messageStore = transactionLog; - } - - @Override - public long getTransactionStartTime() - { - return 0L; - } - - @Override - public long getTransactionUpdateTime() - { - return 0L; - } - - /** - * Since AutoCommitTransaction have no concept of a long lived transaction, any Actions registered - * by the caller are executed immediately. - */ - public void addPostTransactionAction(final Action immediateAction) - { - immediateAction.postCommit(); - } - - public void dequeue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction) - { - Transaction txn = null; - try - { - if(message.isPersistent() && queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Dequeue of message number " + message.getMessageNumber() + " from transaction log. Queue : " + queue.getName()); - } - - txn = _messageStore.newTransaction(); - txn.dequeueMessage(queue, message); - txn.commitTran(); - txn = null; - } - postTransactionAction.postCommit(); - postTransactionAction = null; - } - catch (AMQException e) - { - _logger.error("Error during message dequeue", e); - throw new RuntimeException("Error during message dequeue", e); - } - finally - { - rollbackIfNecessary(postTransactionAction, txn); - } - - } - - public void dequeue(Collection<QueueEntry> queueEntries, Action postTransactionAction) - { - Transaction txn = null; - try - { - for(QueueEntry entry : queueEntries) - { - ServerMessage message = entry.getMessage(); - BaseQueue queue = entry.getQueue(); - - if(message.isPersistent() && queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Dequeue of message number " + message.getMessageNumber() + " from transaction log. Queue : " + queue.getName()); - } - - if(txn == null) - { - txn = _messageStore.newTransaction(); - } - - txn.dequeueMessage(queue, message); - } - - } - if(txn != null) - { - txn.commitTran(); - txn = null; - } - postTransactionAction.postCommit(); - postTransactionAction = null; - } - catch (AMQException e) - { - _logger.error("Error during message dequeues", e); - throw new RuntimeException("Error during message dequeues", e); - } - finally - { - rollbackIfNecessary(postTransactionAction, txn); - } - - } - - - public void enqueue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction) - { - Transaction txn = null; - try - { - if(message.isPersistent() && queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getName()); - } - - txn = _messageStore.newTransaction(); - txn.enqueueMessage(queue, message); - txn.commitTran(); - txn = null; - } - postTransactionAction.postCommit(); - postTransactionAction = null; - } - catch (AMQException e) - { - _logger.error("Error during message enqueue", e); - throw new RuntimeException("Error during message enqueue", e); - } - finally - { - rollbackIfNecessary(postTransactionAction, txn); - } - - - } - - public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction) - { - Transaction txn = null; - try - { - - if(message.isPersistent()) - { - for(BaseQueue queue : queues) - { - if (queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getName()); - } - if (txn == null) - { - txn = _messageStore.newTransaction(); - } - - txn.enqueueMessage(queue, message); - - - } - } - - } - if (txn != null) - { - txn.commitTran(); - txn = null; - } - - postTransactionAction.postCommit(); - postTransactionAction = null; - - - } - catch (AMQException e) - { - _logger.error("Error during message enqueues", e); - throw new RuntimeException("Error during message enqueues", e); - } - finally - { - rollbackIfNecessary(postTransactionAction, txn); - } - - } - - - public void commit(final Runnable immediatePostTransactionAction) - { - immediatePostTransactionAction.run(); - } - - public void commit() - { - } - - public void rollback() - { - } - - public boolean isTransactional() - { - return false; - } - - private void rollbackIfNecessary(Action postTransactionAction, Transaction txn) - { - if (txn != null) - { - try - { - txn.abortTran(); - } - catch (AMQStoreException e) - { - _logger.error("Abort transaction failed", e); - // Deliberate decision not to re-throw this exception. Rationale: we can only reach here if a previous - // TransactionLog method has ended in Exception. If we were to re-throw here, we would prevent - // our caller from receiving the original exception (which is likely to be more revealing of the underlying error). - } - } - if (postTransactionAction != null) - { - postTransactionAction.onRollback(); - } - } - - - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DistributedTransaction.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DistributedTransaction.java deleted file mode 100644 index ab987f0fb9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DistributedTransaction.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.queue.QueueEntry; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.transport.Xid; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class DistributedTransaction implements ServerTransaction -{ - - private final AutoCommitTransaction _autoCommitTransaction; - - private DtxBranch _branch; - private AMQSessionModel _session; - private VirtualHost _vhost; - - - public DistributedTransaction(AMQSessionModel session, MessageStore store, VirtualHost vhost) - { - _session = session; - _vhost = vhost; - _autoCommitTransaction = new AutoCommitTransaction(vhost.getMessageStore()); - } - - @Override - public long getTransactionStartTime() - { - return 0; - } - - @Override - public long getTransactionUpdateTime() - { - return 0; - } - - public void addPostTransactionAction(Action postTransactionAction) - { - if(_branch != null) - { - _branch.addPostTransactionAcion(postTransactionAction); - } - else - { - _autoCommitTransaction.addPostTransactionAction(postTransactionAction); - } - } - - public void dequeue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction) - { - if(_branch != null) - { - _branch.dequeue(queue, message); - _branch.addPostTransactionAcion(postTransactionAction); - } - else - { - _autoCommitTransaction.dequeue(queue, message, postTransactionAction); - } - } - - public void dequeue(Collection<QueueEntry> messages, Action postTransactionAction) - { - if(_branch != null) - { - for(QueueEntry entry : messages) - { - _branch.dequeue(entry.getQueue(), entry.getMessage()); - } - _branch.addPostTransactionAcion(postTransactionAction); - } - else - { - _autoCommitTransaction.dequeue(messages, postTransactionAction); - } - } - - public void enqueue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction) - { - if(_branch != null) - { - _branch.enqueue(queue, message); - _branch.addPostTransactionAcion(postTransactionAction); - enqueue(Collections.singletonList(queue), message, postTransactionAction); - } - else - { - _autoCommitTransaction.enqueue(queue, message, postTransactionAction); - } - } - - public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, - Action postTransactionAction) - { - if(_branch != null) - { - for(BaseQueue queue : queues) - { - _branch.enqueue(queue, message); - } - _branch.addPostTransactionAcion(postTransactionAction); - } - else - { - _autoCommitTransaction.enqueue(queues, message, postTransactionAction); - } - } - - public void commit() - { - throw new IllegalStateException("Cannot call tx.commit() on a distributed transaction"); - } - - public void commit(Runnable immediatePostTransactionAction) - { - throw new IllegalStateException("Cannot call tx.commit() on a distributed transaction"); - } - - public void rollback() - { - throw new IllegalStateException("Cannot call tx.rollback() on a distributed transaction"); - } - - public boolean isTransactional() - { - return _branch != null; - } - - public void start(Xid id, boolean join, boolean resume) - throws UnknownDtxBranchException, AlreadyKnownDtxException, JoinAndResumeDtxException - { - if(join && resume) - { - throw new JoinAndResumeDtxException(id); - } - - DtxBranch branch = _vhost.getDtxRegistry().getBranch(id); - - if(branch == null) - { - if(join || resume) - { - throw new UnknownDtxBranchException(id); - } - branch = new DtxBranch(id,_vhost.getMessageStore(), _vhost); - if(_vhost.getDtxRegistry().registerBranch(branch)) - { - _branch = branch; - branch.associateSession(_session); - } - else - { - throw new AlreadyKnownDtxException(id); - } - } - else - { - if(join) - { - branch.associateSession(_session); - } - else if(resume) - { - branch.resumeSession(_session); - } - else - { - throw new AlreadyKnownDtxException(id); - } - _branch = branch; - } - } - - public void end(Xid id, boolean fail, boolean suspend) - throws UnknownDtxBranchException, NotAssociatedDtxException, SuspendAndFailDtxException, TimeoutDtxException - { - DtxBranch branch = _vhost.getDtxRegistry().getBranch(id); - - if(suspend && fail) - { - branch.disassociateSession(_session); - _branch = null; - throw new SuspendAndFailDtxException(id); - } - - - if(branch == null) - { - throw new UnknownDtxBranchException(id); - } - else - { - if(!branch.isAssociated(_session)) - { - throw new NotAssociatedDtxException(id); - } - if(branch.expired() || branch.getState() == DtxBranch.State.TIMEDOUT) - { - branch.disassociateSession(_session); - throw new TimeoutDtxException(id); - } - - if(suspend) - { - branch.suspendSession(_session); - } - else - { - if(fail) - { - branch.setState(DtxBranch.State.ROLLBACK_ONLY); - } - branch.disassociateSession(_session); - } - - _branch = null; - - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxBranch.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxBranch.java deleted file mode 100644 index fb32b654ce..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxBranch.java +++ /dev/null @@ -1,413 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ScheduledFuture; - -import org.apache.log4j.Logger; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.Transaction; -import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.transport.Xid; - -public class DtxBranch -{ - private static final Logger _logger = Logger.getLogger(DtxBranch.class); - - private final Xid _xid; - private final List<ServerTransaction.Action> _postTransactionActions = new ArrayList<ServerTransaction.Action>(); - private State _state = State.ACTIVE; - private long _timeout; - private Map<AMQSessionModel, State> _associatedSessions = new HashMap<AMQSessionModel, State>(); - private final List<Record> _enqueueRecords = new ArrayList<Record>(); - private final List<Record> _dequeueRecords = new ArrayList<Record>(); - - private Transaction _transaction; - private long _expiration; - private VirtualHost _vhost; - private ScheduledFuture<?> _timeoutFuture; - private MessageStore _store; - - - public enum State - { - ACTIVE, - PREPARED, - TIMEDOUT, - SUSPENDED, - FORGOTTEN, - HEUR_COM, - HEUR_RB, - ROLLBACK_ONLY - } - - - public DtxBranch(Xid xid, MessageStore store, VirtualHost vhost) - { - _xid = xid; - _store = store; - _vhost = vhost; - } - - public Xid getXid() - { - return _xid; - } - - public State getState() - { - return _state; - } - - public void setState(State state) - { - _state = state; - } - - public long getTimeout() - { - return _timeout; - } - - public void setTimeout(long timeout) - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Setting timeout to " + timeout + "s for DtxBranch " + _xid); - } - - if(_timeoutFuture != null) - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Attempting to cancel previous timeout task future for DtxBranch " + _xid); - } - - boolean succeeded = _timeoutFuture.cancel(false); - - if(_logger.isDebugEnabled()) - { - _logger.debug("Cancelling previous timeout task " + (succeeded ? "succeeded" : "failed") - + " for DtxBranch " + _xid); - } - } - - _timeout = timeout; - _expiration = timeout == 0 ? 0 : System.currentTimeMillis() + (1000 * timeout); - - if(_timeout == 0) - { - _timeoutFuture = null; - } - else - { - long delay = 1000*_timeout; - - if(_logger.isDebugEnabled()) - { - _logger.debug("Scheduling timeout and rollback after " + delay/1000 + - "s for DtxBranch " + _xid); - } - - _timeoutFuture = _vhost.scheduleTask(delay, new Runnable() - { - public void run() - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Timing out DtxBranch " + _xid); - } - - setState(State.TIMEDOUT); - try - { - rollback(); - } - catch (AMQStoreException e) - { - _logger.error("Unexpected error when attempting to rollback DtxBranch "+ _xid + " due to timeout", e); - throw new RuntimeException(e); - } - } - }); - } - } - - public boolean expired() - { - return _timeout != 0 && _expiration < System.currentTimeMillis(); - } - - public synchronized boolean isAssociated(AMQSessionModel session) - { - return _associatedSessions.containsKey(session); - } - - public synchronized boolean hasAssociatedSessions() - { - return !_associatedSessions.isEmpty(); - } - - - public synchronized boolean hasAssociatedActiveSessions() - { - if(hasAssociatedSessions()) - { - for(State state : _associatedSessions.values()) - { - if(state != State.SUSPENDED) - { - return true; - } - } - } - return false; - } - - public synchronized void clearAssociations() - { - _associatedSessions.clear(); - } - - synchronized boolean associateSession(AMQSessionModel associatedSession) - { - return _associatedSessions.put(associatedSession, State.ACTIVE) != null; - } - - synchronized boolean disassociateSession(AMQSessionModel associatedSession) - { - return _associatedSessions.remove(associatedSession) != null; - } - - public synchronized boolean resumeSession(AMQSessionModel session) - { - if(_associatedSessions.containsKey(session) && _associatedSessions.get(session) == State.SUSPENDED) - { - _associatedSessions.put(session, State.ACTIVE); - return true; - } - return false; - } - - public synchronized boolean suspendSession(AMQSessionModel session) - { - if(_associatedSessions.containsKey(session) && _associatedSessions.get(session) == State.ACTIVE) - { - _associatedSessions.put(session, State.SUSPENDED); - return true; - } - return false; - } - - public void prepare() throws AMQStoreException - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Performing prepare for DtxBranch " + _xid); - } - - Transaction txn = _store.newTransaction(); - txn.recordXid(_xid.getFormat(), - _xid.getGlobalId(), - _xid.getBranchId(), - _enqueueRecords.toArray(new Record[_enqueueRecords.size()]), - _dequeueRecords.toArray(new Record[_dequeueRecords.size()])); - txn.commitTran(); - - prePrepareTransaction(); - } - - public synchronized void rollback() throws AMQStoreException - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Performing rollback for DtxBranch " + _xid); - } - - if(_timeoutFuture != null) - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Attempting to cancel previous timeout task future for DtxBranch " + _xid); - } - - boolean succeeded = _timeoutFuture.cancel(false); - _timeoutFuture = null; - - if(_logger.isDebugEnabled()) - { - _logger.debug("Cancelling previous timeout task " + (succeeded ? "succeeded" : "failed") - + " for DtxBranch " + _xid); - } - } - - if(_transaction != null) - { - // prepare has previously been called - - Transaction txn = _store.newTransaction(); - txn.removeXid(_xid.getFormat(), _xid.getGlobalId(), _xid.getBranchId()); - txn.commitTran(); - - _transaction.abortTran(); - } - - for(ServerTransaction.Action action : _postTransactionActions) - { - action.onRollback(); - } - _postTransactionActions.clear(); - } - - public void commit() throws AMQStoreException - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Performing commit for DtxBranch " + _xid); - } - - if(_timeoutFuture != null) - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Attempting to cancel previous timeout task future for DtxBranch " + _xid); - } - - boolean succeeded = _timeoutFuture.cancel(false); - _timeoutFuture = null; - - if(_logger.isDebugEnabled()) - { - _logger.debug("Cancelling previous timeout task " + (succeeded ? "succeeded" : "failed") - + " for DtxBranch " + _xid); - } - } - - if(_transaction == null) - { - prePrepareTransaction(); - } - else - { - _transaction.removeXid(_xid.getFormat(), _xid.getGlobalId(), _xid.getBranchId()); - } - _transaction.commitTran(); - - for(ServerTransaction.Action action : _postTransactionActions) - { - action.postCommit(); - } - _postTransactionActions.clear(); - } - - public void prePrepareTransaction() throws AMQStoreException - { - _transaction = _store.newTransaction(); - - for(Record enqueue : _enqueueRecords) - { - if(enqueue.isDurable()) - { - _transaction.enqueueMessage(enqueue.getQueue(), enqueue.getMessage()); - } - } - - - for(Record enqueue : _dequeueRecords) - { - if(enqueue.isDurable()) - { - _transaction.dequeueMessage(enqueue.getQueue(), enqueue.getMessage()); - } - } - } - - - public void addPostTransactionAcion(ServerTransaction.Action postTransactionAction) - { - _postTransactionActions.add(postTransactionAction); - } - - - public void dequeue(BaseQueue queue, EnqueableMessage message) - { - _dequeueRecords.add(new Record(queue, message)); - } - - - public void enqueue(BaseQueue queue, EnqueableMessage message) - { - _enqueueRecords.add(new Record(queue, message)); - } - - private static final class Record implements Transaction.Record - { - private final BaseQueue _queue; - private final EnqueableMessage _message; - - public Record(BaseQueue queue, EnqueableMessage message) - { - _queue = queue; - _message = message; - } - - public BaseQueue getQueue() - { - return _queue; - } - - public EnqueableMessage getMessage() - { - return _message; - } - - public boolean isDurable() - { - return _message.isPersistent() && _queue.isDurable(); - } - } - - - public void close() - { - if(_transaction != null) - { - try - { - _state = null; - _transaction.abortTran(); - } - catch(AMQStoreException e) - { - _logger.error("Error while closing DtxBranch " + _xid, e); - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxException.java deleted file mode 100644 index d18d0cb68b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -public class DtxException extends Exception -{ - public DtxException() - { - } - - public DtxException(String message) - { - super(message); - } - - public DtxException(String message, Throwable cause) - { - super(message, cause); - } - - public DtxException(Throwable cause) - { - super(cause); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxNotSelectedException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxNotSelectedException.java deleted file mode 100644 index c1289b1fdd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxNotSelectedException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -public class DtxNotSelectedException extends DtxException -{ - public DtxNotSelectedException() - { - super("Distribution transactions have not been selected on this session"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxRegistry.java deleted file mode 100644 index 117beb82ef..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/DtxRegistry.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.transport.Xid; - -public class DtxRegistry -{ - private final Map<ComparableXid, DtxBranch> _branches = new HashMap<ComparableXid, DtxBranch>(); - - - private static final class ComparableXid - { - private final Xid _xid; - - private ComparableXid(Xid xid) - { - _xid = xid; - } - - @Override - public boolean equals(Object o) - { - if(this == o) - { - return true; - } - if(o == null || getClass() != o.getClass()) - { - return false; - } - - ComparableXid that = (ComparableXid) o; - - return compareBytes(_xid.getBranchId(), that._xid.getBranchId()) - && compareBytes(_xid.getGlobalId(), that._xid.getGlobalId()); - } - - private static boolean compareBytes(byte[] a, byte[] b) - { - if(a.length != b.length) - { - return false; - } - for(int i = 0; i < a.length; i++) - { - if(a[i] != b[i]) - { - return false; - } - } - return true; - } - - - @Override - public int hashCode() - { - int result = 0; - for(int i = 0; i < _xid.getGlobalId().length; i++) - { - result = 31 * result + (int) _xid.getGlobalId()[i]; - } - for(int i = 0; i < _xid.getBranchId().length; i++) - { - result = 31 * result + (int) _xid.getBranchId()[i]; - } - - return result; - } - } - - public synchronized DtxBranch getBranch(Xid xid) - { - return _branches.get(new ComparableXid(xid)); - } - - public synchronized boolean registerBranch(DtxBranch branch) - { - ComparableXid xid = new ComparableXid(branch.getXid()); - if(!_branches.containsKey(xid)) - { - _branches.put(xid, branch); - return true; - } - return false; - } - - synchronized boolean unregisterBranch(DtxBranch branch) - { - return (_branches.remove(new ComparableXid(branch.getXid())) != null); - } - - public synchronized void commit(Xid id, boolean onePhase) - throws IncorrectDtxStateException, UnknownDtxBranchException, AMQStoreException, RollbackOnlyDtxException, TimeoutDtxException - { - DtxBranch branch = getBranch(id); - if(branch != null) - { - synchronized (branch) - { - if(!branch.hasAssociatedActiveSessions()) - { - branch.clearAssociations(); - - if(branch.expired() || branch.getState() == DtxBranch.State.TIMEDOUT) - { - unregisterBranch(branch); - throw new TimeoutDtxException(id); - } - else if(branch.getState() == DtxBranch.State.ROLLBACK_ONLY) - { - throw new RollbackOnlyDtxException(id); - } - else if(onePhase && branch.getState() == DtxBranch.State.PREPARED) - { - throw new IncorrectDtxStateException("Cannot call one-phase commit on a prepared branch", id); - } - else if(!onePhase && branch.getState() != DtxBranch.State.PREPARED) - { - throw new IncorrectDtxStateException("Cannot call two-phase commit on a non-prepared branch", - id); - } - branch.commit(); - branch.setState(DtxBranch.State.FORGOTTEN); - unregisterBranch(branch); - } - else - { - throw new IncorrectDtxStateException("Branch was still associated with a session", id); - } - } - } - else - { - throw new UnknownDtxBranchException(id); - } - } - - public synchronized void prepare(Xid id) - throws UnknownDtxBranchException, - IncorrectDtxStateException, AMQStoreException, RollbackOnlyDtxException, TimeoutDtxException - { - DtxBranch branch = getBranch(id); - if(branch != null) - { - synchronized (branch) - { - if(!branch.hasAssociatedActiveSessions()) - { - branch.clearAssociations(); - - if(branch.expired() || branch.getState() == DtxBranch.State.TIMEDOUT) - { - unregisterBranch(branch); - throw new TimeoutDtxException(id); - } - else if(branch.getState() != DtxBranch.State.ACTIVE - && branch.getState() != DtxBranch.State.ROLLBACK_ONLY) - { - throw new IncorrectDtxStateException("Cannot prepare a transaction in state " - + branch.getState(), id); - } - else - { - branch.prepare(); - branch.setState(DtxBranch.State.PREPARED); - } - } - else - { - throw new IncorrectDtxStateException("Branch still has associated sessions", id); - } - } - } - else - { - throw new UnknownDtxBranchException(id); - } - } - - public synchronized void rollback(Xid id) - throws IncorrectDtxStateException, - UnknownDtxBranchException, - AMQStoreException, TimeoutDtxException - { - - DtxBranch branch = getBranch(id); - if(branch != null) - { - synchronized (branch) - { - if(branch.expired() || branch.getState() == DtxBranch.State.TIMEDOUT) - { - unregisterBranch(branch); - throw new TimeoutDtxException(id); - } - if(!branch.hasAssociatedActiveSessions()) - { - branch.clearAssociations(); - branch.rollback(); - branch.setState(DtxBranch.State.FORGOTTEN); - unregisterBranch(branch); - } - else - { - throw new IncorrectDtxStateException("Branch was still associated with a session", id); - } - } - } - else - { - throw new UnknownDtxBranchException(id); - } - } - - - public void forget(Xid id) throws UnknownDtxBranchException, IncorrectDtxStateException - { - DtxBranch branch = getBranch(id); - if(branch != null) - { - synchronized (branch) - { - if(!branch.hasAssociatedSessions()) - { - if(branch.getState() != DtxBranch.State.HEUR_COM && branch.getState() != DtxBranch.State.HEUR_RB) - { - throw new IncorrectDtxStateException("Branch should not be forgotten - " - + "it is not heuristically complete", id); - } - branch.setState(DtxBranch.State.FORGOTTEN); - unregisterBranch(branch); - } - else - { - throw new IncorrectDtxStateException("Branch was still associated with a session", id); - } - } - } - else - { - throw new UnknownDtxBranchException(id); - } - } - - public long getTimeout(Xid id) throws UnknownDtxBranchException - { - DtxBranch branch = getBranch(id); - if(branch != null) - { - return branch.getTimeout(); - } - else - { - throw new UnknownDtxBranchException(id); - } - } - - public void setTimeout(Xid id, long timeout) throws UnknownDtxBranchException - { - DtxBranch branch = getBranch(id); - if(branch != null) - { - branch.setTimeout(timeout); - } - else - { - throw new UnknownDtxBranchException(id); - } - } - - public synchronized List<Xid> recover() - { - List<Xid> inDoubt = new ArrayList<Xid>(); - for(DtxBranch branch : _branches.values()) - { - if(branch.getState() == DtxBranch.State.PREPARED) - { - inDoubt.add(branch.getXid()); - } - } - return inDoubt; - } - - public synchronized void endAssociations(AMQSessionModel session) - { - for(DtxBranch branch : _branches.values()) - { - if(branch.isAssociated(session)) - { - branch.setState(DtxBranch.State.ROLLBACK_ONLY); - branch.disassociateSession(session); - } - } - - } - - - public synchronized void close() - { - for(DtxBranch branch : _branches.values()) - { - branch.close(); - } - _branches.clear(); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/IncorrectDtxStateException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/IncorrectDtxStateException.java deleted file mode 100644 index 45f094e4b9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/IncorrectDtxStateException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.transport.Xid; - -public class IncorrectDtxStateException extends DtxException -{ - public IncorrectDtxStateException(String message, Xid id) - { - super(message + " (xid: " + id + ")"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/JoinAndResumeDtxException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/JoinAndResumeDtxException.java deleted file mode 100644 index a25e5a4ed6..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/JoinAndResumeDtxException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.transport.Xid; - -public class JoinAndResumeDtxException extends DtxException -{ - public JoinAndResumeDtxException(Xid id) - { - super("Cannot start a branch with both join and resume set " + id); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/LocalTransaction.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/LocalTransaction.java deleted file mode 100755 index 23265199c7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/LocalTransaction.java +++ /dev/null @@ -1,483 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.server.store.StoreFuture; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.queue.QueueEntry; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.Transaction; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * A concrete implementation of ServerTransaction where enqueue/dequeue - * operations share a single long-lived transaction. - * - * The caller is responsible for invoking commit() (or rollback()) as necessary. - */ -public class LocalTransaction implements ServerTransaction -{ - protected static final Logger _logger = LoggerFactory.getLogger(LocalTransaction.class); - - private final List<Action> _postTransactionActions = new ArrayList<Action>(); - - private volatile Transaction _transaction; - private final ActivityTimeAccessor _activityTime; - private final MessageStore _transactionLog; - private volatile long _txnStartTime = 0L; - private volatile long _txnUpdateTime = 0l; - private StoreFuture _asyncTran; - - public LocalTransaction(MessageStore transactionLog) - { - this(transactionLog, new ActivityTimeAccessor() - { - @Override - public long getActivityTime() - { - return System.currentTimeMillis(); - } - }); - } - - public LocalTransaction(MessageStore transactionLog, ActivityTimeAccessor activityTime) - { - _transactionLog = transactionLog; - _activityTime = activityTime; - } - - @Override - public long getTransactionStartTime() - { - return _txnStartTime; - } - - @Override - public long getTransactionUpdateTime() - { - return _txnUpdateTime; - } - - public void addPostTransactionAction(Action postTransactionAction) - { - sync(); - _postTransactionActions.add(postTransactionAction); - } - - public void dequeue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction) - { - sync(); - _postTransactionActions.add(postTransactionAction); - initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime(); - - if(message.isPersistent() && queue.isDurable()) - { - try - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Dequeue of message number " + message.getMessageNumber() + " from transaction log. Queue : " + queue.getName()); - } - - beginTranIfNecessary(); - _transaction.dequeueMessage(queue, message); - - } - catch(AMQException e) - { - _logger.error("Error during message dequeues", e); - tidyUpOnError(e); - } - } - } - - public void dequeue(Collection<QueueEntry> queueEntries, Action postTransactionAction) - { - sync(); - _postTransactionActions.add(postTransactionAction); - initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime(); - - try - { - for(QueueEntry entry : queueEntries) - { - ServerMessage message = entry.getMessage(); - BaseQueue queue = entry.getQueue(); - - if(message.isPersistent() && queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Dequeue of message number " + message.getMessageNumber() + " from transaction log. Queue : " + queue.getName()); - } - - beginTranIfNecessary(); - _transaction.dequeueMessage(queue, message); - } - - } - } - catch(AMQException e) - { - _logger.error("Error during message dequeues", e); - tidyUpOnError(e); - } - } - - private void tidyUpOnError(Exception e) - { - try - { - doRollbackActions(); - } - finally - { - try - { - if (_transaction != null) - { - _transaction.abortTran(); - } - } - catch (Exception abortException) - { - _logger.error("Abort transaction failed while trying to handle previous error", abortException); - } - finally - { - resetDetails(); - } - } - - throw new RuntimeException(e); - } - - private void beginTranIfNecessary() - { - - if(_transaction == null) - { - try - { - _transaction = _transactionLog.newTransaction(); - } - catch (Exception e) - { - tidyUpOnError(e); - } - } - } - - public void enqueue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction) - { - sync(); - _postTransactionActions.add(postTransactionAction); - initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime(); - - if(message.isPersistent() && queue.isDurable()) - { - try - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getName()); - } - - beginTranIfNecessary(); - _transaction.enqueueMessage(queue, message); - } - catch (Exception e) - { - _logger.error("Error during message enqueue", e); - - tidyUpOnError(e); - } - } - } - - public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction) - { - sync(); - _postTransactionActions.add(postTransactionAction); - initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime(); - - if(message.isPersistent()) - { - try - { - for(BaseQueue queue : queues) - { - if(queue.isDurable()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getName() ); - } - - beginTranIfNecessary(); - _transaction.enqueueMessage(queue, message); - } - } - - } - catch (Exception e) - { - _logger.error("Error during message enqueue", e); - - tidyUpOnError(e); - } - } - } - - public void commit() - { - sync(); - commit(null); - } - - public void commit(Runnable immediateAction) - { - sync(); - try - { - if(_transaction != null) - { - _transaction.commitTran(); - } - - if(immediateAction != null) - { - immediateAction.run(); - } - - doPostTransactionActions(); - } - catch (Exception e) - { - _logger.error("Failed to commit transaction", e); - - doRollbackActions(); - throw new RuntimeException("Failed to commit transaction", e); - } - finally - { - resetDetails(); - } - } - - private void doRollbackActions() - { - for(Action action : _postTransactionActions) - { - action.onRollback(); - } - } - - public StoreFuture commitAsync(final Runnable deferred) - { - sync(); - try - { - StoreFuture future = StoreFuture.IMMEDIATE_FUTURE; - if(_transaction != null) - { - future = new StoreFuture() - { - private volatile boolean _completed = false; - private StoreFuture _underlying = _transaction.commitTranAsync(); - - @Override - public boolean isComplete() - { - return _completed || checkUnderlyingCompletion(); - } - - @Override - public void waitForCompletion() - { - if(!_completed) - { - _underlying.waitForCompletion(); - checkUnderlyingCompletion(); - } - } - - private synchronized boolean checkUnderlyingCompletion() - { - if(!_completed && _underlying.isComplete()) - { - completeDeferredWork(); - _completed = true; - } - return _completed; - - } - - private void completeDeferredWork() - { - try - { - doPostTransactionActions(); - deferred.run(); - - } - catch (Exception e) - { - _logger.error("Failed to commit transaction", e); - - doRollbackActions(); - throw new RuntimeException("Failed to commit transaction", e); - } - finally - { - resetDetails(); - } - } - - }; - _asyncTran = future; - } - else - { - try - { - doPostTransactionActions(); - - deferred.run(); - } - finally - { - resetDetails(); - } - } - - return future; - } - catch (Exception e) - { - _logger.error("Failed to commit transaction", e); - try - { - doRollbackActions(); - } - finally - { - resetDetails(); - } - throw new RuntimeException("Failed to commit transaction", e); - } - } - - private void doPostTransactionActions() - { - if(_logger.isDebugEnabled()) - { - _logger.debug("Beginning " + _postTransactionActions.size() + " post transaction actions"); - } - - for(int i = 0; i < _postTransactionActions.size(); i++) - { - _postTransactionActions.get(i).postCommit(); - } - - if(_logger.isDebugEnabled()) - { - _logger.debug("Completed post transaction actions"); - } - } - - public void rollback() - { - sync(); - try - { - if(_transaction != null) - { - _transaction.abortTran(); - } - } - catch (AMQException e) - { - _logger.error("Failed to rollback transaction", e); - throw new RuntimeException("Failed to rollback transaction", e); - } - finally - { - try - { - doRollbackActions(); - } - finally - { - resetDetails(); - } - } - } - - public void sync() - { - if(_asyncTran != null) - { - _asyncTran.waitForCompletion(); - _asyncTran = null; - } - } - - private void initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime() - { - long currentTime = _activityTime.getActivityTime(); - - if (_txnStartTime == 0) - { - _txnStartTime = currentTime; - } - _txnUpdateTime = currentTime; - } - - private void resetDetails() - { - _asyncTran = null; - _transaction = null; - _postTransactionActions.clear(); - _txnStartTime = 0L; - _txnUpdateTime = 0; - } - - public boolean isTransactional() - { - return true; - } - - public interface ActivityTimeAccessor - { - long getActivityTime(); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/NotAssociatedDtxException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/NotAssociatedDtxException.java deleted file mode 100644 index de070546a7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/NotAssociatedDtxException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.transport.Xid; - -public class NotAssociatedDtxException extends DtxException -{ - public NotAssociatedDtxException(Xid id) - { - super("Xid " + id + " not associated with the current session"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/RollbackOnlyDtxException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/RollbackOnlyDtxException.java deleted file mode 100644 index 6cf12d8631..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/RollbackOnlyDtxException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.transport.Xid; - -public class RollbackOnlyDtxException extends DtxException -{ - public RollbackOnlyDtxException(Xid id) - { - super("Transaction " + id + " may only be rolled back"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java deleted file mode 100755 index 8acac00479..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import java.util.Collection; -import java.util.List; -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.queue.QueueEntry; - - -/** - * The ServerTransaction interface allows a set enqueue/dequeue operations to be - * performed against the transaction belonging the underlying TransactionLog object. - * - * Typically all ServerTransaction implementations decide if a message should be enlisted - * into a store transaction by examining the durable property of the queue, and the persistence - * property of the message. - * - * A caller may register a list of post transaction Actions to be - * performed on commit() (or rollback()). - * - */ -public interface ServerTransaction -{ - - - /** - * Represents an action to be performed on transaction commit or rollback - */ - public static interface Action - { - public void postCommit(); - - public void onRollback(); - } - - /** - * Return the time the current transaction started. - * - * @return the time this transaction started or 0 if not in a transaction - */ - long getTransactionStartTime(); - - /** - * Return the time of the last activity on the current transaction. - * - * @return the time of the last activity or 0 if not in a transaction - */ - long getTransactionUpdateTime(); - - /** - * Register an Action for execution after transaction commit or rollback. Actions - * will be executed in the order in which they are registered. - */ - void addPostTransactionAction(Action postTransactionAction); - - /** - * Dequeue a message from a queue registering a post transaction action. - * - * A store operation will result only for a persistent message on a durable queue. - */ - void dequeue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction); - - /** - * Dequeue a message(s) from queue(s) registering a post transaction action. - * - * Store operations will result only for a persistent messages on durable queues. - */ - void dequeue(Collection<QueueEntry> messages, Action postTransactionAction); - - /** - * Enqueue a message to a queue registering a post transaction action. - * - * A store operation will result only for a persistent message on a durable queue. - */ - void enqueue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction); - - /** - * Enqueue a message(s) to queue(s) registering a post transaction action. - * - * Store operations will result only for a persistent messages on durable queues. - */ - void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction); - - /** - * Commit the transaction represented by this object. - * - * If the caller has registered one or more Actions, the postCommit() method on each will - * be executed immediately after the underlying transaction has committed. - */ - void commit(); - - void commit(Runnable immediatePostTransactionAction); - - /** Rollback the transaction represented by this object. - * - * If the caller has registered one or more Actions, the onRollback() method on each will - * be executed immediately after the underlying transaction has rolled-back. - */ - void rollback(); - - boolean isTransactional(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/SuspendAndFailDtxException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/SuspendAndFailDtxException.java deleted file mode 100644 index 228844fd63..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/SuspendAndFailDtxException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.transport.Xid; - -public class SuspendAndFailDtxException extends DtxException -{ -public SuspendAndFailDtxException(Xid id) -{ - super("Cannot end a branch with both suspend and fail set " + id); -} -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/TimeoutDtxException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/TimeoutDtxException.java deleted file mode 100644 index 50f7708d8a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/TimeoutDtxException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.transport.Xid; - -public class TimeoutDtxException extends DtxException -{ - public TimeoutDtxException(Xid id) - { - super("Transaction " + id + " has timed-out and may only be rolled back"); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/UnknownDtxBranchException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/UnknownDtxBranchException.java deleted file mode 100644 index c23e518365..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/txn/UnknownDtxBranchException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.txn; - -import org.apache.qpid.transport.Xid; - -public class UnknownDtxBranchException extends DtxException -{ - public UnknownDtxBranchException(Xid id) - { - super("Unknown xid " + id); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ByteBufferOutputStream.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ByteBufferOutputStream.java deleted file mode 100644 index ca9a41bc32..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ByteBufferOutputStream.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.util; - -import java.io.OutputStream; -import java.nio.ByteBuffer; - -public class ByteBufferOutputStream extends OutputStream -{ - private final ByteBuffer _buffer; - - public ByteBufferOutputStream(ByteBuffer buffer) - { - _buffer = buffer; - } - - @Override - public void write(int b) - { - _buffer.put((byte)b); - } - - @Override - public void write(byte[] b, int off, int len) - { - _buffer.put(b, off, len); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapJsonSerializer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapJsonSerializer.java deleted file mode 100644 index 2d9ba38555..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapJsonSerializer.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.util; - -import java.io.StringWriter; -import java.util.Map; - -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; - -public class MapJsonSerializer -{ - private static final TypeReference<Map<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<Map<String, Object>>() - { - }; - - private ObjectMapper _mapper; - - public MapJsonSerializer() - { - _mapper = new ObjectMapper(); - } - - public String serialize(Map<String, Object> attributeMap) - { - StringWriter stringWriter = new StringWriter(); - try - { - _mapper.writeValue(stringWriter, attributeMap); - } - catch (Exception e) - { - throw new RuntimeException("Failure to serialize map:" + attributeMap, e); - } - return stringWriter.toString(); - } - - public Map<String, Object> deserialize(String json) - { - Map<String, Object> attributesMap = null; - try - { - attributesMap = _mapper.readValue(json, MAP_TYPE_REFERENCE); - } - catch (Exception e) - { - throw new RuntimeException("Failure to deserialize json:" + json, e); - } - return attributesMap; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java deleted file mode 100644 index 37e0177b00..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java +++ /dev/null @@ -1,412 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.util; - -import java.lang.reflect.Array; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class MapValueConverter -{ - - public static String getStringAttribute(String name, Map<String,Object> attributes, String defaultVal) - { - final Object value = attributes.get(name); - return toString(value, defaultVal); - } - - public static String toString(final Object value) - { - return toString(value, null); - } - - public static String toString(final Object value, String defaultVal) - { - if (value == null) - { - return defaultVal; - } - else if (value instanceof String) - { - return (String)value; - } - return String.valueOf(value); - } - - public static String getStringAttribute(String name, Map<String, Object> attributes) - { - assertMandatoryAttribute(name, attributes); - return getStringAttribute(name, attributes, null); - } - - public static void assertMandatoryAttribute(String name, Map<String, Object> attributes) - { - if (!attributes.containsKey(name)) - { - throw new IllegalArgumentException("Value for attribute " + name + " is not found"); - } - } - - public static Map<String,Object> getMapAttribute(String name, Map<String,Object> attributes, Map<String,Object> defaultVal) - { - final Object value = attributes.get(name); - if(value == null) - { - return defaultVal; - } - else if(value instanceof Map) - { - @SuppressWarnings("unchecked") - Map<String,Object> retVal = (Map<String,Object>) value; - return retVal; - } - else - { - throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Map"); - } - } - - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static <E extends Enum> E getEnumAttribute(Class<E> clazz, String name, Map<String,Object> attributes, E defaultVal) - { - Object obj = attributes.get(name); - if(obj == null) - { - return defaultVal; - } - else if(clazz.isInstance(obj)) - { - return (E) obj; - } - else if(obj instanceof String) - { - return (E) Enum.valueOf(clazz, (String)obj); - } - else - { - throw new IllegalArgumentException("Value for attribute " + name + " is not of required type " + clazz.getSimpleName()); - } - } - - public static <E extends Enum<?>> E getEnumAttribute(Class<E> clazz, String name, Map<String,Object> attributes) - { - assertMandatoryAttribute(name, attributes); - return getEnumAttribute(clazz, name, attributes, null); - } - - @SuppressWarnings({ "unchecked" }) - public static <T extends Enum<T>> T toEnum(String name, Object rawValue, Class<T> enumType) - { - if (enumType.isInstance(rawValue)) - { - return (T) rawValue; - } - else if (rawValue instanceof String) - { - final String stringValue = (String) rawValue; - - return "null".equals(stringValue) ? null : (T) Enum.valueOf(enumType, stringValue); - } - else if(rawValue == null) - { - return null; - } - else - { - throw new IllegalArgumentException("Value for attribute " + name + " is not of required type " - + enumType.getSimpleName()); - } - } - - public static Boolean getBooleanAttribute(String name, Map<String,Object> attributes, Boolean defaultValue) - { - Object obj = attributes.get(name); - return toBoolean(name, obj, defaultValue); - } - - public static Boolean toBoolean(String name, Object obj) - { - return toBoolean(name, obj, null); - } - - public static Boolean toBoolean(String name, Object obj, Boolean defaultValue) - { - if(obj == null) - { - return defaultValue; - } - else if(obj instanceof Boolean) - { - return (Boolean) obj; - } - else if(obj instanceof String) - { - return Boolean.parseBoolean((String) obj); - } - else - { - throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Boolean"); - } - } - - - public static boolean getBooleanAttribute(String name, Map<String, Object> attributes) - { - assertMandatoryAttribute(name, attributes); - return getBooleanAttribute(name, attributes, null); - } - - public static Integer getIntegerAttribute(String name, Map<String,Object> attributes, Integer defaultValue) - { - Object obj = attributes.get(name); - return toInteger(name, obj, defaultValue); - } - - public static Integer toInteger(String name, Object obj) - { - return toInteger(name, obj, null); - } - - public static Integer toInteger(String name, Object obj, Integer defaultValue) - { - if(obj == null) - { - return defaultValue; - } - else if(obj instanceof Number) - { - return ((Number) obj).intValue(); - } - else if(obj instanceof String) - { - return Integer.valueOf((String) obj); - } - else - { - throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Integer"); - } - } - - public static Integer getIntegerAttribute(String name, Map<String,Object> attributes) - { - assertMandatoryAttribute(name, attributes); - return getIntegerAttribute(name, attributes, null); - } - - public static Long getLongAttribute(String name, Map<String,Object> attributes, Long defaultValue) - { - Object obj = attributes.get(name); - return toLong(name, obj, defaultValue); - } - - public static Long toLong(String name, Object obj) - { - return toLong(name, obj, null); - } - - public static Long toLong(String name, Object obj, Long defaultValue) - { - if(obj == null) - { - return defaultValue; - } - else if(obj instanceof Number) - { - return ((Number) obj).longValue(); - } - else if(obj instanceof String) - { - return Long.valueOf((String) obj); - } - else - { - throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Long"); - } - } - - public static <T> Set<T> getSetAttribute(String name, Map<String,Object> attributes) - { - assertMandatoryAttribute(name, attributes); - return getSetAttribute(name, attributes, Collections.<T>emptySet()); - } - - @SuppressWarnings("unchecked") - public static <T> Set<T> getSetAttribute(String name, Map<String,Object> attributes, Set<T> defaultValue) - { - Object obj = attributes.get(name); - if(obj == null) - { - return defaultValue; - } - else if(obj instanceof Set) - { - return (Set<T>) obj; - } - else - { - throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Set"); - } - } - - public static <T extends Enum<T>> Set<T> getEnumSetAttribute(String name, Map<String, Object> attributes, Class<T> clazz) - { - Object obj = attributes.get(name); - if (obj == null) - { - return null; - } - else - { - return toSet(obj, clazz, name); - } - } - - public static Map<String, Object> convert(Map<String, Object> configurationAttributes, Map<String, Type> attributeTypes) - { - return convert(configurationAttributes, attributeTypes, true); - } - - public static Map<String, Object> convert(Map<String, Object> configurationAttributes, - Map<String, Type> attributeTypes, - boolean exclusive) - { - Map<String, Object> attributes = new HashMap<String, Object>(); - for (Map.Entry<String, Object> attribute : configurationAttributes.entrySet()) - { - String attributeName = attribute.getKey(); - Object rawValue = attribute.getValue(); - - if (attributeTypes.containsKey(attributeName)) - { - Type typeObject = attributeTypes.get(attributeName); - - Object value = null; - if (typeObject instanceof Class) - { - Class<?> classObject = (Class<?>)typeObject; - value = convert(rawValue, classObject, attributeName); - } - else if (typeObject instanceof ParameterizedType) - { - ParameterizedType parameterizedType= (ParameterizedType)typeObject; - Type type = parameterizedType.getRawType(); - if (type == Set.class) - { - Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); - if (actualTypeArguments.length != 1) - { - throw new IllegalArgumentException("Set type argument is not specified"); - } - Class<?> classObject = (Class<?>)actualTypeArguments[0]; - value = toSet(rawValue, classObject, attributeName); - } - else - { - throw new IllegalArgumentException("Conversion into " + parameterizedType + " is not yet supported"); - } - } - else - { - throw new IllegalArgumentException("Conversion into " + typeObject + " is not yet supported"); - } - attributes.put(attributeName, value); - } - else if(!exclusive) - { - attributes.put(attributeName, rawValue); - } - } - - return attributes; - } - - public static <T> Set<T> toSet(Object rawValue, Class<T> setItemClass, String attributeName) - { - if (rawValue == null) - { - return null; - } - HashSet<T> set = new HashSet<T>(); - if (rawValue instanceof Iterable) - { - Iterable<?> iterable = (Iterable<?>)rawValue; - for (Object object : iterable) - { - T converted = convert(object, setItemClass, attributeName); - set.add(converted); - } - } - else if (rawValue.getClass().isArray()) - { - int length = Array.getLength(rawValue); - for (int i = 0; i < length; i ++) - { - Object arrayElement = Array.get(rawValue, i); - T converted = convert(arrayElement, setItemClass, attributeName); - set.add(converted); - } - } - else - { - throw new IllegalArgumentException("Cannot convert '" + rawValue.getClass() + "' into Set<" + setItemClass.getSimpleName() + "> for attribute " + attributeName); - } - return set; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static <T> T convert(Object rawValue, Class<T> classObject, String attributeName) - { - Object value; - if (classObject == Long.class || classObject == long.class) - { - value = toLong(attributeName, rawValue); - } - else if (classObject == Integer.class || classObject == int.class) - { - value = toInteger(attributeName, rawValue); - } - else if (classObject == Boolean.class || classObject == boolean.class) - { - value = toBoolean(attributeName, rawValue); - } - else if (classObject == String.class) - { - value = toString(rawValue); - } - else if (Enum.class.isAssignableFrom(classObject)) - { - value = toEnum(attributeName, rawValue, (Class<Enum>) classObject); - } - else - { - throw new IllegalArgumentException("Cannot convert '" + rawValue + "' of type '" + rawValue.getClass() - + "' into type " + classObject + " for attribute " + attributeName); - } - return (T) value; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ParameterizedTypeImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ParameterizedTypeImpl.java deleted file mode 100644 index 29bc81caab..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ParameterizedTypeImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.util; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -public class ParameterizedTypeImpl implements ParameterizedType -{ - private Class<?> _rawType; - private Type[] _typeArguments; - - public ParameterizedTypeImpl(Class<?> rawType, Class<?>... typeArguments) - { - _rawType = rawType; - _typeArguments = typeArguments; - } - @Override - public Type[] getActualTypeArguments() - { - return _typeArguments; - } - - @Override - public Type getRawType() - { - return _rawType; - } - - @Override - public Type getOwnerType() - { - return _rawType.getDeclaringClass(); - } - - @Override - public String toString() - { - StringBuilder sb = new StringBuilder(_rawType.getName()); - if (_typeArguments != null) - { - sb.append("<"); - for (int i = 0; i < _typeArguments.length; i++) - { - sb.append(_typeArguments[i].getClass().getName()); - if (i < _typeArguments.length - 1) - { - sb.append(","); - } - } - sb.append(">"); - } - return sb.toString(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ResourceBundleLoader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ResourceBundleLoader.java deleted file mode 100644 index a0ed4e27f4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/ResourceBundleLoader.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.util; - -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class ResourceBundleLoader -{ - public static Map<String, String> getResources(String baseName) - { - try - { - ResourceBundle bundle = ResourceBundle.getBundle(baseName); - Map<String, String> resources = new HashMap<String, String>(); - Enumeration<String> en = bundle.getKeys(); - while (en.hasMoreElements()) - { - String key = (String) en.nextElement(); - resources.put(key, bundle.getString(key)); - } - return resources; - } - catch(MissingResourceException e) - { - return null; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/StringUtil.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/StringUtil.java deleted file mode 100644 index aa17a9493b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/StringUtil.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.util; - -import java.util.Random; - -public class StringUtil -{ - private static final String NUMBERS = "0123456789"; - private static final String LETTERS = "abcdefghijklmnopqrstuvwxwy"; - private static final String OTHERS = "_-"; - private static final char[] CHARACTERS = (NUMBERS + LETTERS + LETTERS.toUpperCase() + OTHERS).toCharArray(); - - private Random _random = new Random(); - - public String randomAlphaNumericString(int maxLength) - { - char[] result = new char[maxLength]; - for (int i = 0; i < maxLength; i++) - { - result[i] = (char) CHARACTERS[_random.nextInt(CHARACTERS.length)]; - } - return new String(result); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java deleted file mode 100644 index 0cd4f0b6b2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java +++ /dev/null @@ -1,930 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.configuration.ConfigurationException; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.server.configuration.ExchangeConfiguration; -import org.apache.qpid.server.configuration.QueueConfiguration; -import org.apache.qpid.server.configuration.VirtualHostConfiguration; -import org.apache.qpid.server.connection.ConnectionRegistry; -import org.apache.qpid.server.connection.IConnectionRegistry; -import org.apache.qpid.server.exchange.DefaultExchangeFactory; -import org.apache.qpid.server.exchange.DefaultExchangeRegistry; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.exchange.ExchangeFactory; -import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.VirtualHostMessages; -import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.protocol.AMQConnectionModel; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.protocol.LinkRegistry; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.AMQQueueFactory; -import org.apache.qpid.server.queue.DefaultQueueRegistry; -import org.apache.qpid.server.queue.QueueRegistry; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.stats.StatisticsCounter; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.store.DurableConfigurationStoreHelper; -import org.apache.qpid.server.store.DurableConfiguredObjectRecoverer; -import org.apache.qpid.server.store.Event; -import org.apache.qpid.server.store.EventListener; -import org.apache.qpid.server.txn.DtxRegistry; -import org.apache.qpid.server.virtualhost.plugins.QueueExistsException; - -public abstract class AbstractVirtualHost implements VirtualHost, IConnectionRegistry.RegistryChangeListener, EventListener -{ - private static final Logger _logger = Logger.getLogger(AbstractVirtualHost.class); - - private static final int HOUSEKEEPING_SHUTDOWN_TIMEOUT = 5; - - private final String _name; - - private final UUID _id; - - private final long _createTime = System.currentTimeMillis(); - - private final ScheduledThreadPoolExecutor _houseKeepingTasks; - - private final VirtualHostRegistry _virtualHostRegistry; - - private final StatisticsGatherer _brokerStatisticsGatherer; - - private final SecurityManager _securityManager; - - private final VirtualHostConfiguration _vhostConfig; - - private final QueueRegistry _queueRegistry; - - private final ExchangeRegistry _exchangeRegistry; - - private final ExchangeFactory _exchangeFactory; - - private final ConnectionRegistry _connectionRegistry; - - private final DtxRegistry _dtxRegistry; - private final AMQQueueFactory _queueFactory; - - private volatile State _state = State.INITIALISING; - - private StatisticsCounter _messagesDelivered, _dataDelivered, _messagesReceived, _dataReceived; - - private final Map<String, LinkRegistry> _linkRegistry = new HashMap<String, LinkRegistry>(); - private boolean _blocked; - - public AbstractVirtualHost(VirtualHostRegistry virtualHostRegistry, - StatisticsGatherer brokerStatisticsGatherer, - SecurityManager parentSecurityManager, - VirtualHostConfiguration hostConfig, - org.apache.qpid.server.model.VirtualHost virtualHost) throws Exception - { - if (hostConfig == null) - { - throw new IllegalArgumentException("HostConfig cannot be null"); - } - - if (hostConfig.getName() == null || hostConfig.getName().length() == 0) - { - throw new IllegalArgumentException("Illegal name (" + hostConfig.getName() + ") for virtualhost."); - } - - _virtualHostRegistry = virtualHostRegistry; - _brokerStatisticsGatherer = brokerStatisticsGatherer; - _vhostConfig = hostConfig; - _name = _vhostConfig.getName(); - _dtxRegistry = new DtxRegistry(); - - _id = UUIDGenerator.generateVhostUUID(_name); - - CurrentActor.get().message(VirtualHostMessages.CREATED(_name)); - - _securityManager = new SecurityManager(parentSecurityManager, _vhostConfig.getConfig().getString("security.acl"), _name); - - _connectionRegistry = new ConnectionRegistry(); - _connectionRegistry.addRegistryChangeListener(this); - - _houseKeepingTasks = new ScheduledThreadPoolExecutor(_vhostConfig.getHouseKeepingThreadCount()); - - - _queueRegistry = new DefaultQueueRegistry(this); - - _queueFactory = new AMQQueueFactory(this, _queueRegistry); - - _exchangeFactory = new DefaultExchangeFactory(this); - - _exchangeRegistry = new DefaultExchangeRegistry(this, _queueRegistry); - - initialiseStatistics(); - - initialiseStorage(hostConfig, virtualHost); - - getMessageStore().addEventListener(this, Event.PERSISTENT_MESSAGE_SIZE_OVERFULL); - getMessageStore().addEventListener(this, Event.PERSISTENT_MESSAGE_SIZE_UNDERFULL); - } - - abstract protected void initialiseStorage(VirtualHostConfiguration hostConfig, - org.apache.qpid.server.model.VirtualHost virtualHost) throws Exception; - - public IConnectionRegistry getConnectionRegistry() - { - return _connectionRegistry; - } - - public VirtualHostConfiguration getConfiguration() - { - return _vhostConfig; - } - - public UUID getId() - { - return _id; - } - - public boolean isDurable() - { - return false; - } - - /** - * Initialise a housekeeping task to iterate over queues cleaning expired messages with no consumers - * and checking for idle or open transactions that have exceeded the permitted thresholds. - * - * @param period - */ - private void initialiseHouseKeeping(long period) - { - if (period != 0L) - { - scheduleHouseKeepingTask(period, new VirtualHostHouseKeepingTask()); - } - } - - protected void shutdownHouseKeeping() - { - _houseKeepingTasks.shutdown(); - - try - { - if (!_houseKeepingTasks.awaitTermination(HOUSEKEEPING_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) - { - _houseKeepingTasks.shutdownNow(); - } - } - catch (InterruptedException e) - { - _logger.warn("Interrupted during Housekeeping shutdown:", e); - Thread.currentThread().interrupt(); - } - } - - protected void removeHouseKeepingTasks() - { - BlockingQueue<Runnable> taskQueue = _houseKeepingTasks.getQueue(); - for (final Runnable runnable : taskQueue) - { - _houseKeepingTasks.remove(runnable); - } - } - - /** - * Allow other broker components to register a HouseKeepingTask - * - * @param period How often this task should run, in ms. - * @param task The task to run. - */ - public void scheduleHouseKeepingTask(long period, HouseKeepingTask task) - { - _houseKeepingTasks.scheduleAtFixedRate(task, period / 2, period, - TimeUnit.MILLISECONDS); - } - - public ScheduledFuture<?> scheduleTask(long delay, Runnable task) - { - return _houseKeepingTasks.schedule(task, delay, TimeUnit.MILLISECONDS); - } - - public long getHouseKeepingTaskCount() - { - return _houseKeepingTasks.getTaskCount(); - } - - public long getHouseKeepingCompletedTaskCount() - { - return _houseKeepingTasks.getCompletedTaskCount(); - } - - public int getHouseKeepingPoolSize() - { - return _houseKeepingTasks.getCorePoolSize(); - } - - public void setHouseKeepingPoolSize(int newSize) - { - _houseKeepingTasks.setCorePoolSize(newSize); - } - - - public int getHouseKeepingActiveCount() - { - return _houseKeepingTasks.getActiveCount(); - } - - - protected void initialiseModel(VirtualHostConfiguration config) throws ConfigurationException, AMQException - { - _logger.debug("Loading configuration for virtualhost: " + config.getName()); - - _exchangeRegistry.initialise(_exchangeFactory); - - List<String> exchangeNames = config.getExchanges(); - - for (String exchangeName : exchangeNames) - { - configureExchange(config.getExchangeConfiguration(exchangeName)); - } - - String[] queueNames = config.getQueueNames(); - - for (Object queueNameObj : queueNames) - { - String queueName = String.valueOf(queueNameObj); - configureQueue(config.getQueueConfiguration(queueName)); - } - } - - private void configureExchange(ExchangeConfiguration exchangeConfiguration) throws AMQException - { - boolean durable = exchangeConfiguration.getDurable(); - boolean autodelete = exchangeConfiguration.getAutoDelete(); - try - { - Exchange newExchange = createExchange(null, exchangeConfiguration.getName(), exchangeConfiguration.getType(), durable, autodelete, - null); - } - catch(ExchangeExistsException e) - { - _logger.info("Exchange " + exchangeConfiguration.getName() + " already defined. Configuration in XML file ignored"); - } - - } - - private void configureQueue(QueueConfiguration queueConfiguration) throws AMQException, ConfigurationException - { - AMQQueue queue = _queueFactory.createAMQQueueImpl(queueConfiguration); - String queueName = queue.getName(); - - if (queue.isDurable()) - { - DurableConfigurationStoreHelper.createQueue(getDurableConfigurationStore(), queue); - } - - //get the exchange name (returns default exchange name if none was specified) - String exchangeName = queueConfiguration.getExchange(); - - Exchange exchange = _exchangeRegistry.getExchange(exchangeName); - if (exchange == null) - { - throw new ConfigurationException("Attempt to bind queue '" + queueName + "' to unknown exchange:" + exchangeName); - } - - Exchange defaultExchange = _exchangeRegistry.getDefaultExchange(); - - //get routing keys in configuration (returns empty list if none are defined) - List<?> routingKeys = queueConfiguration.getRoutingKeys(); - - for (Object routingKeyNameObj : routingKeys) - { - String routingKey = String.valueOf(routingKeyNameObj); - - if (exchange.equals(defaultExchange)) - { - if(!queueName.equals(routingKey)) - { - throw new ConfigurationException("Illegal attempt to bind queue '" + queueName + - "' to the default exchange with a key other than the queue name: " + routingKey); - } - } - else - { - configureBinding(queue, exchange, routingKey, (Map) queueConfiguration.getBindingArguments(routingKey)); - } - } - - if (!exchange.equals(defaultExchange) && !routingKeys.contains(queueName)) - { - //bind the queue to the named exchange using its name - configureBinding(queue, exchange, queueName, null); - } - - } - - private void configureBinding(AMQQueue queue, Exchange exchange, String routingKey, Map<String,Object> arguments) throws AMQException - { - if (_logger.isInfoEnabled()) - { - _logger.info("Binding queue:" + queue + " with routing key '" + routingKey + "' to exchange:" + exchange.getName()); - } - exchange.addBinding(routingKey, queue, arguments); - } - - public String getName() - { - return _name; - } - - public long getCreateTime() - { - return _createTime; - } - - public QueueRegistry getQueueRegistry() - { - return _queueRegistry; - } - - protected ExchangeRegistry getExchangeRegistry() - { - return _exchangeRegistry; - } - - protected ExchangeFactory getExchangeFactory() - { - return _exchangeFactory; - } - - @Override - public void addVirtualHostListener(final VirtualHostListener listener) - { - _exchangeRegistry.addRegistryChangeListener(new ExchangeRegistry.RegistryChangeListener() - { - @Override - public void exchangeRegistered(Exchange exchange) - { - listener.exchangeRegistered(exchange); - } - - @Override - public void exchangeUnregistered(Exchange exchange) - { - listener.exchangeUnregistered(exchange); - } - }); - _queueRegistry.addRegistryChangeListener(new QueueRegistry.RegistryChangeListener() - { - @Override - public void queueRegistered(AMQQueue queue) - { - listener.queueRegistered(queue); - } - - @Override - public void queueUnregistered(AMQQueue queue) - { - listener.queueUnregistered(queue); - } - }); - _connectionRegistry.addRegistryChangeListener(new IConnectionRegistry.RegistryChangeListener() - { - @Override - public void connectionRegistered(AMQConnectionModel connection) - { - listener.connectionRegistered(connection); - } - - @Override - public void connectionUnregistered(AMQConnectionModel connection) - { - listener.connectionUnregistered(connection); - } - }); - } - - @Override - public AMQQueue getQueue(String name) - { - return _queueRegistry.getQueue(name); - } - - @Override - public AMQQueue getQueue(UUID id) - { - return _queueRegistry.getQueue(id); - } - - @Override - public Collection<AMQQueue> getQueues() - { - return _queueRegistry.getQueues(); - } - - @Override - public int removeQueue(AMQQueue queue) throws AMQException - { - synchronized (getQueueRegistry()) - { - int purged = queue.delete(); - - getQueueRegistry().unregisterQueue(queue.getName()); - if (queue.isDurable() && !queue.isAutoDelete()) - { - DurableConfigurationStore store = getDurableConfigurationStore(); - DurableConfigurationStoreHelper.removeQueue(store, queue); - } - return purged; - } - } - - @Override - public AMQQueue createQueue(UUID id, - String queueName, - boolean durable, - String owner, - boolean autoDelete, - boolean exclusive, - boolean deleteOnNoConsumer, - Map<String, Object> arguments) throws AMQException - { - - if (queueName == null) - { - throw new IllegalArgumentException("Queue name must not be null"); - } - - // Access check - if (!getSecurityManager().authoriseCreateQueue(autoDelete, - durable, - exclusive, - null, - null, - queueName, - owner)) - { - String description = "Permission denied: queue-name '" + queueName + "'"; - throw new AMQSecurityException(description); - } - - synchronized (_queueRegistry) - { - if(_queueRegistry.getQueue(queueName) != null) - { - throw new QueueExistsException("Queue with name " + queueName + " already exists", _queueRegistry.getQueue(queueName)); - } - if(id == null) - { - - id = UUIDGenerator.generateExchangeUUID(queueName, getName()); - while(_queueRegistry.getQueue(id) != null) - { - id = UUID.randomUUID(); - } - - } - else if(_queueRegistry.getQueue(id) != null) - { - throw new QueueExistsException("Queue with id " + id + " already exists", _queueRegistry.getQueue(queueName)); - } - return _queueFactory.createQueue(id, queueName, durable, owner, autoDelete, exclusive, deleteOnNoConsumer, - arguments); - } - - } - - @Override - public Exchange getExchange(String name) - { - return _exchangeRegistry.getExchange(name); - } - - @Override - public Exchange getExchange(UUID id) - { - return _exchangeRegistry.getExchange(id); - } - - @Override - public Exchange getDefaultExchange() - { - return _exchangeRegistry.getDefaultExchange(); - } - - @Override - public Collection<Exchange> getExchanges() - { - return Collections.unmodifiableCollection(_exchangeRegistry.getExchanges()); - } - - @Override - public Collection<ExchangeType<? extends Exchange>> getExchangeTypes() - { - return _exchangeFactory.getRegisteredTypes(); - } - - @Override - public Exchange createExchange(UUID id, - String name, - String type, - boolean durable, - boolean autoDelete, - String alternateExchangeName) - throws AMQException - { - - if(_exchangeRegistry.isReservedExchangeName(name)) - { - throw new ReservedExchangeNameException(name); - } - synchronized (_exchangeRegistry) - { - Exchange existing; - if((existing = _exchangeRegistry.getExchange(name)) !=null) - { - throw new ExchangeExistsException(name,existing); - } - Exchange alternateExchange; - - if(alternateExchangeName != null) - { - alternateExchange = _exchangeRegistry.getExchange(alternateExchangeName); - if(alternateExchange == null) - { - throw new UnknownExchangeException(alternateExchangeName); - } - } - else - { - alternateExchange = null; - } - - if(id == null) - { - id = UUIDGenerator.generateExchangeUUID(name, getName()); - } - - Exchange exchange = _exchangeFactory.createExchange(id, name, type, durable, autoDelete); - exchange.setAlternateExchange(alternateExchange); - _exchangeRegistry.registerExchange(exchange); - if(durable) - { - DurableConfigurationStoreHelper.createExchange(getDurableConfigurationStore(), exchange); - } - return exchange; - } - } - - @Override - public void removeExchange(Exchange exchange, boolean force) throws AMQException - { - if(exchange.hasReferrers()) - { - throw new ExchangeIsAlternateException(exchange.getName()); - } - - for(ExchangeType type : getExchangeTypes()) - { - if(type.getDefaultExchangeName().equals( exchange.getName() )) - { - throw new RequiredExchangeException(exchange.getName()); - } - } - _exchangeRegistry.unregisterExchange(exchange.getName(), !force); - if (exchange.isDurable() && !exchange.isAutoDelete()) - { - DurableConfigurationStoreHelper.removeExchange(getDurableConfigurationStore(), exchange); - } - - } - - public SecurityManager getSecurityManager() - { - return _securityManager; - } - - public void close() - { - //Stop Connections - _connectionRegistry.close(); - _queueRegistry.stopAllAndUnregisterMBeans(); - _dtxRegistry.close(); - closeStorage(); - shutdownHouseKeeping(); - - // clear exchange objects - _exchangeRegistry.clearAndUnregisterMbeans(); - - _state = State.STOPPED; - - CurrentActor.get().message(VirtualHostMessages.CLOSED()); - } - - protected void closeStorage() - { - //Close MessageStore - if (getMessageStore() != null) - { - //Remove MessageStore Interface should not throw Exception - try - { - getMessageStore().close(); - } - catch (Exception e) - { - _logger.error("Failed to close message store", e); - } - } - if (getDurableConfigurationStore() != null) - { - //Remove MessageStore Interface should not throw Exception - try - { - getDurableConfigurationStore().close(); - } - catch (Exception e) - { - _logger.error("Failed to close message store", e); - } - } - } - - - protected Logger getLogger() - { - return _logger; - } - - - - public VirtualHostRegistry getVirtualHostRegistry() - { - return _virtualHostRegistry; - } - - public void registerMessageDelivered(long messageSize) - { - _messagesDelivered.registerEvent(1L); - _dataDelivered.registerEvent(messageSize); - _brokerStatisticsGatherer.registerMessageDelivered(messageSize); - } - - public void registerMessageReceived(long messageSize, long timestamp) - { - _messagesReceived.registerEvent(1L, timestamp); - _dataReceived.registerEvent(messageSize, timestamp); - _brokerStatisticsGatherer.registerMessageReceived(messageSize, timestamp); - } - - public StatisticsCounter getMessageReceiptStatistics() - { - return _messagesReceived; - } - - public StatisticsCounter getDataReceiptStatistics() - { - return _dataReceived; - } - - public StatisticsCounter getMessageDeliveryStatistics() - { - return _messagesDelivered; - } - - public StatisticsCounter getDataDeliveryStatistics() - { - return _dataDelivered; - } - - public void resetStatistics() - { - _messagesDelivered.reset(); - _dataDelivered.reset(); - _messagesReceived.reset(); - _dataReceived.reset(); - - for (AMQConnectionModel connection : _connectionRegistry.getConnections()) - { - connection.resetStatistics(); - } - } - - public void initialiseStatistics() - { - _messagesDelivered = new StatisticsCounter("messages-delivered-" + getName()); - _dataDelivered = new StatisticsCounter("bytes-delivered-" + getName()); - _messagesReceived = new StatisticsCounter("messages-received-" + getName()); - _dataReceived = new StatisticsCounter("bytes-received-" + getName()); - } - - public synchronized LinkRegistry getLinkRegistry(String remoteContainerId) - { - LinkRegistry linkRegistry = _linkRegistry.get(remoteContainerId); - if(linkRegistry == null) - { - linkRegistry = new LinkRegistry(); - _linkRegistry.put(remoteContainerId, linkRegistry); - } - return linkRegistry; - } - - public DtxRegistry getDtxRegistry() - { - return _dtxRegistry; - } - - public String toString() - { - return _name; - } - - public State getState() - { - return _state; - } - - public void block() - { - synchronized (_connectionRegistry) - { - if(!_blocked) - { - _blocked = true; - for(AMQConnectionModel conn : _connectionRegistry.getConnections()) - { - conn.block(); - } - } - } - } - - - public void unblock() - { - synchronized (_connectionRegistry) - { - if(_blocked) - { - _blocked = false; - for(AMQConnectionModel conn : _connectionRegistry.getConnections()) - { - conn.unblock(); - } - } - } - } - - public void connectionRegistered(final AMQConnectionModel connection) - { - if(_blocked) - { - connection.block(); - } - } - - public void connectionUnregistered(final AMQConnectionModel connection) - { - } - - public void event(final Event event) - { - switch(event) - { - case PERSISTENT_MESSAGE_SIZE_OVERFULL: - block(); - break; - case PERSISTENT_MESSAGE_SIZE_UNDERFULL: - unblock(); - break; - } - } - - protected void setState(State state) - { - _state = state; - } - - protected void attainActivation() - { - State finalState = State.ERRORED; - - try - { - initialiseHouseKeeping(_vhostConfig.getHousekeepingCheckPeriod()); - finalState = State.ACTIVE; - } - finally - { - _state = finalState; - reportIfError(_state); - } - } - - protected void reportIfError(State state) - { - if (state == State.ERRORED) - { - CurrentActor.get().message(VirtualHostMessages.ERRORED()); - } - } - - protected Map<String, DurableConfiguredObjectRecoverer> getDurableConfigurationRecoverers() - { - DurableConfiguredObjectRecoverer[] recoverers = { - new QueueRecoverer(this, getExchangeRegistry(), _queueFactory), - new ExchangeRecoverer(getExchangeRegistry(), getExchangeFactory()), - new BindingRecoverer(this, getExchangeRegistry()) - }; - - final Map<String, DurableConfiguredObjectRecoverer> recovererMap= new HashMap<String, DurableConfiguredObjectRecoverer>(); - for(DurableConfiguredObjectRecoverer recoverer : recoverers) - { - recovererMap.put(recoverer.getType(), recoverer); - } - return recovererMap; - } - - private class VirtualHostHouseKeepingTask extends HouseKeepingTask - { - public VirtualHostHouseKeepingTask() - { - super(AbstractVirtualHost.this); - } - - public void execute() - { - for (AMQQueue q : _queueRegistry.getQueues()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Checking message status for queue: " - + q.getName()); - } - try - { - q.checkMessageStatus(); - } catch (Exception e) - { - _logger.error("Exception in housekeeping for queue: " + q.getName(), e); - //Don't throw exceptions as this will stop the - // house keeping task from running. - } - } - for (AMQConnectionModel connection : getConnectionRegistry().getConnections()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Checking for long running open transactions on connection " + connection); - } - for (AMQSessionModel session : connection.getSessionModels()) - { - if (_logger.isDebugEnabled()) - { - _logger.debug("Checking for long running open transactions on session " + session); - } - try - { - session.checkTransactionStatus(_vhostConfig.getTransactionTimeoutOpenWarn(), - _vhostConfig.getTransactionTimeoutOpenClose(), - _vhostConfig.getTransactionTimeoutIdleWarn(), - _vhostConfig.getTransactionTimeoutIdleClose()); - } catch (Exception e) - { - _logger.error("Exception in housekeeping for connection: " + connection.toString(), e); - } - } - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/BindingRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/BindingRecoverer.java deleted file mode 100644 index a321c285b7..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/BindingRecoverer.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.store.AbstractDurableConfiguredObjectRecoverer; -import org.apache.qpid.server.store.UnresolvedDependency; -import org.apache.qpid.server.store.UnresolvedObject; - -public class BindingRecoverer extends AbstractDurableConfiguredObjectRecoverer<Binding> -{ - private static final Logger _logger = Logger.getLogger(BindingRecoverer.class); - - private final ExchangeRegistry _exchangeRegistry; - private final VirtualHost _virtualHost; - - public BindingRecoverer(final VirtualHost virtualHost, - final ExchangeRegistry exchangeRegistry) - { - _exchangeRegistry = exchangeRegistry; - _virtualHost = virtualHost; - } - - @Override - public UnresolvedObject<Binding> createUnresolvedObject(final UUID id, - final String type, - final Map<String, Object> attributes) - { - return new UnresolvedBinding(id, attributes); - } - - @Override - public String getType() - { - return org.apache.qpid.server.model.Binding.class.getSimpleName(); - } - - private class UnresolvedBinding implements UnresolvedObject<Binding> - { - private final Map<String, Object> _bindingArgumentsMap; - private final String _bindingName; - private final UUID _queueId; - private final UUID _exchangeId; - private final UUID _bindingId; - - private List<UnresolvedDependency> _unresolvedDependencies = - new ArrayList<UnresolvedDependency>(); - - private Exchange _exchange; - private AMQQueue _queue; - - public UnresolvedBinding(final UUID id, - final Map<String, Object> attributeMap) - { - _bindingId = id; - _exchangeId = UUID.fromString(String.valueOf(attributeMap.get(org.apache.qpid.server.model.Binding.EXCHANGE))); - _queueId = UUID.fromString(String.valueOf(attributeMap.get(org.apache.qpid.server.model.Binding.QUEUE))); - _exchange = _exchangeRegistry.getExchange(_exchangeId); - if(_exchange == null) - { - _unresolvedDependencies.add(new ExchangeDependency()); - } - _queue = _virtualHost.getQueue(_queueId); - if(_queue == null) - { - _unresolvedDependencies.add(new QueueDependency()); - } - - _bindingName = (String) attributeMap.get(org.apache.qpid.server.model.Binding.NAME); - _bindingArgumentsMap = (Map<String, Object>) attributeMap.get(org.apache.qpid.server.model.Binding.ARGUMENTS); - } - - @Override - public UnresolvedDependency[] getUnresolvedDependencies() - { - return _unresolvedDependencies.toArray(new UnresolvedDependency[_unresolvedDependencies.size()]); - } - - @Override - public Binding resolve() - { - try - { - if(_exchange.getBinding(_bindingName, _queue, _bindingArgumentsMap) == null) - { - _logger.info("Restoring binding: (Exchange: " + _exchange.getName() + ", Queue: " + _queue.getName() - + ", Routing Key: " + _bindingName + ", Arguments: " + _bindingArgumentsMap + ")"); - - _exchange.restoreBinding(_bindingId, _bindingName, _queue, _bindingArgumentsMap); - } - return _exchange.getBinding(_bindingName, _queue, _bindingArgumentsMap); - } - catch (AMQException e) - { - throw new RuntimeException(e); - } - } - - private class QueueDependency implements UnresolvedDependency<AMQQueue> - { - - @Override - public UUID getId() - { - return _queueId; - } - - @Override - public String getType() - { - return Queue.class.getSimpleName(); - } - - @Override - public void resolve(final AMQQueue dependency) - { - _queue = dependency; - _unresolvedDependencies.remove(this); - } - - } - - private class ExchangeDependency implements UnresolvedDependency<Exchange> - { - - @Override - public UUID getId() - { - return _exchangeId; - } - - @Override - public String getType() - { - return org.apache.qpid.server.model.Exchange.class.getSimpleName(); - } - - @Override - public void resolve(final Exchange dependency) - { - _exchange = dependency; - _unresolvedDependencies.remove(this); - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/DefaultUpgraderProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/DefaultUpgraderProvider.java deleted file mode 100644 index 8d05e719ee..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/DefaultUpgraderProvider.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; -import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.exchange.FilterSupport; -import org.apache.qpid.server.exchange.TopicExchange; -import org.apache.qpid.server.model.Binding; -import org.apache.qpid.server.model.Exchange; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.queue.QueueArgumentsConverter; -import org.apache.qpid.server.store.ConfiguredObjectRecord; -import org.apache.qpid.server.store.DurableConfigurationRecoverer; -import org.apache.qpid.server.store.DurableConfigurationStoreUpgrader; -import org.apache.qpid.server.store.NonNullUpgrader; -import org.apache.qpid.server.store.NullUpgrader; -import org.apache.qpid.server.store.UpgraderProvider; - -import static org.apache.qpid.server.model.VirtualHost.CURRENT_CONFIG_VERSION; - -public class DefaultUpgraderProvider implements UpgraderProvider -{ - private final ExchangeRegistry _exchangeRegistry; - private final VirtualHost _virtualHost; - - public DefaultUpgraderProvider(final VirtualHost virtualHost, - final ExchangeRegistry exchangeRegistry) - { - _virtualHost = virtualHost; - _exchangeRegistry = exchangeRegistry; - } - - public DurableConfigurationStoreUpgrader getUpgrader(final int configVersion, DurableConfigurationRecoverer recoverer) - { - DurableConfigurationStoreUpgrader currentUpgrader = null; - switch(configVersion) - { - case 0: - currentUpgrader = addUpgrader(currentUpgrader, new Version0Upgrader()); - case 1: - currentUpgrader = addUpgrader(currentUpgrader, new Version1Upgrader()); - case 2: - currentUpgrader = addUpgrader(currentUpgrader, new Version2Upgrader()); - - case CURRENT_CONFIG_VERSION: - currentUpgrader = addUpgrader(currentUpgrader, new NullUpgrader(recoverer)); - break; - - default: - throw new IllegalStateException("Unknown configuration model version: " + configVersion - + ". Attempting to run an older instance against an upgraded configuration?"); - } - return currentUpgrader; - } - - private DurableConfigurationStoreUpgrader addUpgrader(DurableConfigurationStoreUpgrader currentUpgrader, - final DurableConfigurationStoreUpgrader nextUpgrader) - { - if(currentUpgrader == null) - { - currentUpgrader = nextUpgrader; - } - else - { - currentUpgrader.setNextUpgrader(nextUpgrader); - } - return currentUpgrader; - } - - /* - * Removes filters from queue bindings to exchanges other than topic exchanges. In older versions of the broker - * such bindings would have been ignored, starting from the point at which the config version changed, these - * arguments would actually cause selectors to be enforced, thus changing which messages would reach a queue. - */ - private class Version0Upgrader extends NonNullUpgrader - { - private final Map<UUID, ConfiguredObjectRecord> _records = new HashMap<UUID, ConfiguredObjectRecord>(); - - public Version0Upgrader() - { - } - - @Override - public void configuredObject(final UUID id, final String type, Map<String, Object> attributes) - { - _records.put(id, new ConfiguredObjectRecord(id, type, attributes)); - } - - private void removeSelectorArguments(Map<String, Object> binding) - { - @SuppressWarnings("unchecked") - Map<String, Object> arguments = new LinkedHashMap<String, Object>((Map<String,Object>)binding.get(Binding.ARGUMENTS)); - - FilterSupport.removeFilters(arguments); - binding.put(Binding.ARGUMENTS, arguments); - } - - private boolean isTopicExchange(Map<String, Object> binding) - { - UUID exchangeId = UUID.fromString((String)binding.get(Binding.EXCHANGE)); - - if(_records.containsKey(exchangeId)) - { - return "topic".equals(_records.get(exchangeId) - .getAttributes() - .get(org.apache.qpid.server.model.Exchange.TYPE)); - } - else - { - return _exchangeRegistry.getExchange(exchangeId) != null - && _exchangeRegistry.getExchange(exchangeId).getType() == TopicExchange.TYPE; - } - - } - - private boolean hasSelectorArguments(Map<String, Object> binding) - { - @SuppressWarnings("unchecked") - Map<String, Object> arguments = (Map<String, Object>) binding.get(Binding.ARGUMENTS); - return (arguments != null) && FilterSupport.argumentsContainFilter(arguments); - } - - - - @Override - public void complete() - { - for(Map.Entry<UUID,ConfiguredObjectRecord> entry : _records.entrySet()) - { - ConfiguredObjectRecord record = entry.getValue(); - String type = record.getType(); - Map<String, Object> attributes = record.getAttributes(); - UUID id = record.getId(); - if(type.equals(Binding.class.getName()) && hasSelectorArguments(attributes) && !isTopicExchange(attributes)) - { - attributes = new LinkedHashMap<String, Object>(attributes); - removeSelectorArguments(attributes); - - record = new ConfiguredObjectRecord(id, type, attributes); - getUpdateMap().put(id, record); - entry.setValue(record); - - } - getNextUpgrader().configuredObject(id, type, attributes); - } - - getNextUpgrader().complete(); - } - - } - - /* - * Change the type string from org.apache.qpid.server.model.Foo to Foo (in line with the practice in the broker - * configuration store). Also remove bindings which reference non-existant queues or exchanges. - */ - private class Version1Upgrader extends NonNullUpgrader - { - @Override - public void configuredObject(final UUID id, String type, final Map<String, Object> attributes) - { - type = type.substring(1+type.lastIndexOf('.')); - getUpdateMap().put(id, new ConfiguredObjectRecord(id, type, attributes)); - - } - - @Override - public void complete() - { - for(Map.Entry<UUID, ConfiguredObjectRecord> entry : getUpdateMap().entrySet()) - { - final ConfiguredObjectRecord record = entry.getValue(); - if(isBinding(record.getType()) && (unknownExchange((String) record.getAttributes().get(Binding.EXCHANGE)) - || unknownQueue((String) record.getAttributes().get(Binding.QUEUE)))) - { - entry.setValue(null); - } - else - { - getNextUpgrader().configuredObject(record.getId(), record.getType(), record.getAttributes()); - } - } - getNextUpgrader().complete(); - } - - private boolean unknownExchange(final String exchangeIdString) - { - UUID exchangeId = UUID.fromString(exchangeIdString); - ConfiguredObjectRecord localRecord = getUpdateMap().get(exchangeId); - return !((localRecord != null && localRecord.getType().equals(Exchange.class.getSimpleName())) - || _exchangeRegistry.getExchange(exchangeId) != null); - } - - private boolean unknownQueue(final String queueIdString) - { - UUID queueId = UUID.fromString(queueIdString); - ConfiguredObjectRecord localRecord = getUpdateMap().get(queueId); - return !((localRecord != null && localRecord.getType().equals(Queue.class.getSimpleName())) - || _virtualHost.getQueue(queueId) != null); - } - - private boolean isBinding(final String type) - { - return Binding.class.getSimpleName().equals(type); - } - - - } - - /* - * Convert the storage of queue attributes to remove the separate "ARGUMENT" attribute, and flatten the - * attributes into the map using the model attribute names rather than the wire attribute names - */ - private class Version2Upgrader extends NonNullUpgrader - { - - private static final String ARGUMENTS = "arguments"; - - @Override - public void configuredObject(UUID id, String type, Map<String, Object> attributes) - { - if(Queue.class.getSimpleName().equals(type)) - { - Map<String, Object> newAttributes = new LinkedHashMap<String, Object>(); - if(attributes.get(ARGUMENTS) instanceof Map) - { - newAttributes.putAll(QueueArgumentsConverter.convertWireArgsToModel((Map<String, Object>) attributes - .get(ARGUMENTS))); - } - newAttributes.putAll(attributes); - attributes = newAttributes; - getUpdateMap().put(id, new ConfiguredObjectRecord(id,type,attributes)); - } - - getNextUpgrader().configuredObject(id,type,attributes); - } - - @Override - public void complete() - { - getNextUpgrader().complete(); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeExistsException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeExistsException.java deleted file mode 100644 index f055760efe..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeExistsException.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apache.qpid.server.virtualhost;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.exchange.Exchange; - -public class ExchangeExistsException extends AMQException -{ - private final Exchange _existing; - - public ExchangeExistsException(String name, Exchange existing) - { - super(name); - _existing = existing; - } - - public Exchange getExistingExchange() - { - return _existing; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeIsAlternateException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeIsAlternateException.java deleted file mode 100644 index 4be64a3b94..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeIsAlternateException.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apache.qpid.server.virtualhost;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import org.apache.qpid.AMQException; - -public class ExchangeIsAlternateException extends AMQException -{ - public ExchangeIsAlternateException(String name) - { - super(name); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeRecoverer.java deleted file mode 100644 index 6ad7014c47..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ExchangeRecoverer.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -import java.util.Map; -import java.util.UUID; -import org.apache.qpid.AMQException; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.exchange.ExchangeFactory; -import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.model.LifetimePolicy; -import org.apache.qpid.server.store.AbstractDurableConfiguredObjectRecoverer; -import org.apache.qpid.server.store.UnresolvedDependency; -import org.apache.qpid.server.store.UnresolvedObject; - -public class ExchangeRecoverer extends AbstractDurableConfiguredObjectRecoverer<Exchange> -{ - private final ExchangeRegistry _exchangeRegistry; - private final ExchangeFactory _exchangeFactory; - - public ExchangeRecoverer(final ExchangeRegistry exchangeRegistry, final ExchangeFactory exchangeFactory) - { - _exchangeRegistry = exchangeRegistry; - _exchangeFactory = exchangeFactory; - } - - @Override - public String getType() - { - return org.apache.qpid.server.model.Exchange.class.getSimpleName(); - } - - @Override - public UnresolvedObject<Exchange> createUnresolvedObject(final UUID id, - final String type, - final Map<String, Object> attributes) - { - return new UnresolvedExchange(id, attributes); - } - - private class UnresolvedExchange implements UnresolvedObject<Exchange> - { - private Exchange _exchange; - - public UnresolvedExchange(final UUID id, - final Map<String, Object> attributeMap) - { - String exchangeName = (String) attributeMap.get(org.apache.qpid.server.model.Exchange.NAME); - String exchangeType = (String) attributeMap.get(org.apache.qpid.server.model.Exchange.TYPE); - String lifeTimePolicy = (String) attributeMap.get(org.apache.qpid.server.model.Exchange.LIFETIME_POLICY); - boolean autoDelete = lifeTimePolicy == null - || LifetimePolicy.valueOf(lifeTimePolicy) == LifetimePolicy.AUTO_DELETE; - try - { - _exchange = _exchangeRegistry.getExchange(id); - if(_exchange == null) - { - _exchange = _exchangeRegistry.getExchange(exchangeName); - } - if (_exchange == null) - { - _exchange = _exchangeFactory.restoreExchange(id, exchangeName, exchangeType, autoDelete); - _exchangeRegistry.registerExchange(_exchange); - } - } - catch (AMQException e) - { - throw new RuntimeException("Error recovering exchange uuid " + id + " name " + exchangeName, e); - } - } - - @Override - public UnresolvedDependency[] getUnresolvedDependencies() - { - return new UnresolvedDependency[0]; - } - - @Override - public Exchange resolve() - { - return _exchange; - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java deleted file mode 100644 index 1b0e50fd34..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -import org.apache.log4j.Logger; - -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.logging.actors.AbstractActor; -import org.apache.qpid.server.logging.actors.CurrentActor; - -public abstract class HouseKeepingTask implements Runnable -{ - private Logger _logger = Logger.getLogger(this.getClass()); - - private VirtualHost _virtualHost; - - private String _name; - - private RootMessageLogger _rootLogger; - public HouseKeepingTask(VirtualHost vhost) - { - _virtualHost = vhost; - _name = _virtualHost.getName() + ":" + this.getClass().getSimpleName(); - _rootLogger = CurrentActor.get().getRootMessageLogger(); - } - - final public void run() - { - String originalThreadName = Thread.currentThread().getName(); - Thread.currentThread().setName(_name); - - CurrentActor.set(new AbstractActor(_rootLogger) - { - @Override - public String getLogMessage() - { - return _name; - } - }); - - try - { - execute(); - } - catch (Exception e) - { - _logger.warn(this.getClass().getSimpleName() + " throw exception: " + e, e); - } - finally - { - CurrentActor.remove(); - - // eagerly revert the thread name to make thread dumps more meaningful if captured after task has finished - Thread.currentThread().setName(originalThreadName); - } - } - - public VirtualHost getVirtualHost() - { - return _virtualHost; - } - - /** Execute the plugin. */ - public abstract void execute(); - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ManagedVirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ManagedVirtualHost.java deleted file mode 100644 index cb7f213f06..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ManagedVirtualHost.java +++ /dev/null @@ -1,44 +0,0 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.qpid.server.virtualhost;
-
-import org.apache.qpid.management.common.mbeans.annotations.MBeanAttribute;
-
-import java.io.IOException;
-
-/**
- * The management interface exposed to allow management of a virtualHost
- */
-public interface ManagedVirtualHost
-{
- static final String TYPE = "VirtualHost";
- static final int VERSION = 1;
-
- /**
- * Returns the name of the managed virtualHost.
- * @return the name of the exchange.
- * @throws java.io.IOException
- */
- @MBeanAttribute(name="Name", description= TYPE + " Name")
- String getName() throws IOException;
-
-
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/QueueRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/QueueRecoverer.java deleted file mode 100644 index 02d628da68..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/QueueRecoverer.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -import java.util.LinkedHashMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.QueueFactory; -import org.apache.qpid.server.store.AbstractDurableConfiguredObjectRecoverer; -import org.apache.qpid.server.store.UnresolvedDependency; -import org.apache.qpid.server.store.UnresolvedObject; - -public class QueueRecoverer extends AbstractDurableConfiguredObjectRecoverer<AMQQueue> -{ - private static final Logger _logger = Logger.getLogger(QueueRecoverer.class); - private final VirtualHost _virtualHost; - private final ExchangeRegistry _exchangeRegistry; - private final QueueFactory _queueFactory; - - public QueueRecoverer(final VirtualHost virtualHost, - final ExchangeRegistry exchangeRegistry, - final QueueFactory queueFactory) - { - _virtualHost = virtualHost; - _exchangeRegistry = exchangeRegistry; - _queueFactory = queueFactory; - } - - @Override - public String getType() - { - return Queue.class.getSimpleName(); - } - - @Override - public UnresolvedObject<AMQQueue> createUnresolvedObject(final UUID id, - final String type, - final Map<String, Object> attributes) - { - return new UnresolvedQueue(id, type, attributes); - } - - private class UnresolvedQueue implements UnresolvedObject<AMQQueue> - { - private final Map<String, Object> _attributes; - private final UUID _alternateExchangeId; - private final UUID _id; - private AMQQueue _queue; - private List<UnresolvedDependency> _dependencies = new ArrayList<UnresolvedDependency>(); - private Exchange _alternateExchange; - - public UnresolvedQueue(final UUID id, - final String type, - final Map<String, Object> attributes) - { - _attributes = attributes; - _alternateExchangeId = _attributes.get(Queue.ALTERNATE_EXCHANGE) == null ? null : UUID.fromString((String) _attributes - .get(Queue.ALTERNATE_EXCHANGE)); - _id = id; - if (_alternateExchangeId != null) - { - _alternateExchange = _exchangeRegistry.getExchange(_alternateExchangeId); - if(_alternateExchange == null) - { - _dependencies.add(new AlternateExchangeDependency()); - } - } - } - - @Override - public UnresolvedDependency[] getUnresolvedDependencies() - { - return _dependencies.toArray(new UnresolvedDependency[_dependencies.size()]); - } - - @Override - public AMQQueue resolve() - { - String queueName = (String) _attributes.get(Queue.NAME); - String owner = (String) _attributes.get(Queue.OWNER); - boolean exclusive = (Boolean) _attributes.get(Queue.EXCLUSIVE); - - Map<String, Object> queueArgumentsMap = new LinkedHashMap<String, Object>(_attributes); - queueArgumentsMap.remove(Queue.NAME); - queueArgumentsMap.remove(Queue.OWNER); - queueArgumentsMap.remove(Queue.EXCLUSIVE); - - try - { - _queue = _virtualHost.getQueue(_id); - if(_queue == null) - { - _queue = _virtualHost.getQueue(queueName); - } - - if (_queue == null) - { - _queue = _queueFactory.restoreQueue(_id, queueName, owner, false, exclusive, - false, queueArgumentsMap); - } - } - catch (AMQException e) - { - throw new RuntimeException("Error recovering queue uuid " + _id + " name " + queueName, e); - } - return _queue; - } - - private class AlternateExchangeDependency implements UnresolvedDependency - { - @Override - public UUID getId() - { - return _alternateExchangeId; - } - - @Override - public String getType() - { - return "Exchange"; - } - - @Override - public void resolve(final Object dependency) - { - _alternateExchange = (Exchange) dependency; - _dependencies.remove(this); - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/RequiredExchangeException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/RequiredExchangeException.java deleted file mode 100644 index da4c9825b1..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/RequiredExchangeException.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apache.qpid.server.virtualhost;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import org.apache.qpid.AMQException; - -public class RequiredExchangeException extends AMQException -{ - public RequiredExchangeException(String name) - { - super(name); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ReservedExchangeNameException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ReservedExchangeNameException.java deleted file mode 100644 index 585f045ad9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/ReservedExchangeNameException.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apache.qpid.server.virtualhost;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import org.apache.qpid.AMQException; - -public class ReservedExchangeNameException extends AMQException -{ - private final String _name; - - public ReservedExchangeNameException(String name) - { - super("Attempt to create an exchange using a reserved name or prefix: " + name); - _name = name; - } - - public String getName() - { - return _name; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/StandardVirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/StandardVirtualHost.java deleted file mode 100644 index b7e51d88d3..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/StandardVirtualHost.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.apache.qpid.server.virtualhost;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import org.apache.qpid.server.configuration.VirtualHostConfiguration; -import org.apache.qpid.server.logging.subjects.MessageStoreLogSubject; -import org.apache.qpid.server.model.VirtualHost; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.store.DurableConfigurationRecoverer; -import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.store.DurableConfigurationStoreCreator; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.MessageStoreCreator; -import org.apache.qpid.server.store.OperationalLoggingListener; - -public class StandardVirtualHost extends AbstractVirtualHost -{ - private MessageStore _messageStore; - - private DurableConfigurationStore _durableConfigurationStore; - - StandardVirtualHost(VirtualHostRegistry virtualHostRegistry, - StatisticsGatherer brokerStatisticsGatherer, - org.apache.qpid.server.security.SecurityManager parentSecurityManager, - VirtualHostConfiguration hostConfig, VirtualHost virtualHost) throws Exception - { - super(virtualHostRegistry, brokerStatisticsGatherer, parentSecurityManager, hostConfig, virtualHost); - } - - - - private MessageStore initialiseMessageStore(VirtualHostConfiguration hostConfig, VirtualHost virtualHost) throws Exception - { - final Object storeTypeAttr = virtualHost.getAttribute(VirtualHost.STORE_TYPE); - String storeType = storeTypeAttr == null ? null : String.valueOf(storeTypeAttr); - MessageStore messageStore = null; - if (storeType == null) - { - final Class<?> clazz = Class.forName(hostConfig.getMessageStoreClass()); - final Object o = clazz.newInstance(); - - if (!(o instanceof MessageStore)) - { - throw new ClassCastException(clazz + " does not implement " + MessageStore.class); - } - - messageStore = (MessageStore) o; - } - else - { - messageStore = new MessageStoreCreator().createMessageStore(storeType); - } - - final - MessageStoreLogSubject - storeLogSubject = new MessageStoreLogSubject(getName(), messageStore.getClass().getSimpleName()); - OperationalLoggingListener.listen(messageStore, storeLogSubject); - - return messageStore; - } - - private DurableConfigurationStore initialiseConfigurationStore(VirtualHost virtualHost) throws Exception - { - DurableConfigurationStore configurationStore; - final Object storeTypeAttr = virtualHost.getAttribute(VirtualHost.CONFIG_STORE_TYPE); - String storeType = storeTypeAttr == null ? null : String.valueOf(storeTypeAttr); - - if(storeType != null) - { - configurationStore = new DurableConfigurationStoreCreator().createMessageStore(storeType); - } - else if(getMessageStore() instanceof DurableConfigurationStore) - { - configurationStore = (DurableConfigurationStore) getMessageStore(); - } - else - { - throw new ClassCastException(getMessageStore().getClass().getSimpleName() + - " is not an instance of DurableConfigurationStore"); - } - return configurationStore; - } - - - protected void initialiseStorage(VirtualHostConfiguration hostConfig, VirtualHost virtualHost) throws Exception - { - _messageStore = initialiseMessageStore(hostConfig, virtualHost); - - _durableConfigurationStore = initialiseConfigurationStore(virtualHost); - - DurableConfigurationRecoverer configRecoverer = - new DurableConfigurationRecoverer(getName(), getDurableConfigurationRecoverers(), - new DefaultUpgraderProvider(this, getExchangeRegistry())); - _durableConfigurationStore.configureConfigStore(virtualHost, configRecoverer); - - VirtualHostConfigRecoveryHandler recoveryHandler = new VirtualHostConfigRecoveryHandler(this, getExchangeRegistry(), getExchangeFactory()); - _messageStore.configureMessageStore(virtualHost, recoveryHandler, recoveryHandler); - - initialiseModel(hostConfig); - - _messageStore.activate(); - - attainActivation(); - } - - @Override - public MessageStore getMessageStore() - { - return _messageStore; - } - - @Override - public DurableConfigurationStore getDurableConfigurationStore() - { - return _durableConfigurationStore; - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/StandardVirtualHostFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/StandardVirtualHostFactory.java deleted file mode 100644 index 08f35c08f9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/StandardVirtualHostFactory.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.apache.qpid.server.virtualhost;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import java.util.LinkedHashMap; -import java.util.Map; -import org.apache.commons.configuration.Configuration; -import org.apache.qpid.server.configuration.VirtualHostConfiguration; -import org.apache.qpid.server.model.adapter.VirtualHostAdapter; -import org.apache.qpid.server.plugin.MessageStoreFactory; -import org.apache.qpid.server.plugin.VirtualHostFactory; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.store.MessageStoreConstants; -import org.apache.qpid.server.store.MessageStoreCreator; - -public class StandardVirtualHostFactory implements VirtualHostFactory -{ - - public static final String TYPE = "STANDARD"; - - @Override - public String getType() - { - return TYPE; - } - - @Override - public VirtualHost createVirtualHost(VirtualHostRegistry virtualHostRegistry, - StatisticsGatherer brokerStatisticsGatherer, - org.apache.qpid.server.security.SecurityManager parentSecurityManager, - VirtualHostConfiguration hostConfig, - org.apache.qpid.server.model.VirtualHost virtualHost) throws Exception - { - return new StandardVirtualHost(virtualHostRegistry, brokerStatisticsGatherer, parentSecurityManager, hostConfig, virtualHost); - } - - - public static final String STORE_TYPE_ATTRIBUTE = org.apache.qpid.server.model.VirtualHost.STORE_TYPE; - public static final String STORE_PATH_ATTRIBUTE = org.apache.qpid.server.model.VirtualHost.STORE_PATH; - - @Override - public void validateAttributes(Map<String, Object> attributes) - { - - // need store type and path - Object storeType = attributes.get(STORE_TYPE_ATTRIBUTE); - if(!(storeType instanceof String)) - { - - throw new IllegalArgumentException("Attribute '"+ STORE_TYPE_ATTRIBUTE - +"' is required and must be of type String."); - } - final MessageStoreCreator storeCreator = new MessageStoreCreator(); - if(!storeCreator.isValidType((String)storeType)) - { - throw new IllegalArgumentException("Attribute '"+ STORE_TYPE_ATTRIBUTE - +"' has value '"+storeType+"' which is not one of the valid values: " - + storeCreator.getStoreTypes() + "."); - - } - - for(MessageStoreFactory factory : storeCreator.getFactories()) - { - if(factory.getType().equalsIgnoreCase((String)storeType)) - { - factory.validateAttributes(attributes); - } - } - - } - - @Override - public Map<String,Object> createVirtualHostConfiguration(VirtualHostAdapter virtualHostAdapter) - { - Map<String,Object> convertedMap = new LinkedHashMap<String, Object>(); - convertedMap.put("store.type", virtualHostAdapter.getAttribute(org.apache.qpid.server.model.VirtualHost.STORE_TYPE)); - convertedMap.put("store.environment-path", virtualHostAdapter.getAttribute(org.apache.qpid.server.model.VirtualHost.STORE_PATH)); - - return convertedMap; - } - - @Override - public Map<String, Object> convertVirtualHostConfiguration(Configuration configuration) - { - Map<String,Object> convertedMap = new LinkedHashMap<String, Object>(); - Configuration storeConfiguration = configuration.subset("store"); - convertedMap.put(org.apache.qpid.server.model.VirtualHost.STORE_TYPE, storeConfiguration.getString("type")); - convertedMap.put(org.apache.qpid.server.model.VirtualHost.STORE_PATH, storeConfiguration.getString(MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY)); - - convertedMap.put(MessageStoreConstants.OVERFULL_SIZE_ATTRIBUTE, storeConfiguration.getString(MessageStoreConstants.OVERFULL_SIZE_PROPERTY)); - convertedMap.put(MessageStoreConstants.UNDERFULL_SIZE_ATTRIBUTE, storeConfiguration.getString(MessageStoreConstants.UNDERFULL_SIZE_PROPERTY)); - - for(MessageStoreFactory mf : new MessageStoreCreator().getFactories()) - { - convertedMap.putAll(mf.convertStoreConfiguration(storeConfiguration)); - } - - return convertedMap; - - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/State.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/State.java deleted file mode 100644 index 55e2539dcf..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/State.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -public enum State -{ - INITIALISING, - ACTIVE, - PASSIVE, - STOPPED, - /** Terminal state that signifies the virtual host has experienced an unexpected condition. */ - ERRORED -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/UnknownExchangeException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/UnknownExchangeException.java deleted file mode 100644 index 5704126f62..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/UnknownExchangeException.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apache.qpid.server.virtualhost;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import org.apache.qpid.AMQException; - -public class UnknownExchangeException extends AMQException -{ - private final String _exchangeName; - - public UnknownExchangeException(String exchangeName) - { - super(exchangeName); - _exchangeName = exchangeName; - } - - public String getExchangeName() - { - return _exchangeName; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java deleted file mode 100755 index 2ebbedccd4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java +++ /dev/null @@ -1,126 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.virtualhost; - -import java.util.Collection; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ScheduledFuture; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; -import org.apache.qpid.common.Closeable; -import org.apache.qpid.server.configuration.VirtualHostConfiguration; -import org.apache.qpid.server.connection.IConnectionRegistry; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.plugin.ExchangeType; -import org.apache.qpid.server.protocol.LinkRegistry; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.QueueRegistry; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.txn.DtxRegistry; - -public interface VirtualHost extends DurableConfigurationStore.Source, Closeable, StatisticsGatherer -{ - IConnectionRegistry getConnectionRegistry(); - - VirtualHostConfiguration getConfiguration(); - - String getName(); - - AMQQueue getQueue(String name); - - AMQQueue getQueue(UUID id); - - Collection<AMQQueue> getQueues(); - - int removeQueue(AMQQueue queue) throws AMQException; - - AMQQueue createQueue(UUID id, - String queueName, - boolean durable, - String owner, - boolean autoDelete, - boolean exclusive, - boolean deleteOnNoConsumer, - Map<String, Object> arguments) throws AMQException; - - - Exchange createExchange(UUID id, - String exchange, - String type, - boolean durable, - boolean autoDelete, - String alternateExchange) - throws AMQException; - - void removeExchange(Exchange exchange, boolean force) throws AMQException; - - Exchange getExchange(String name); - Exchange getExchange(UUID id); - - - Exchange getDefaultExchange(); - - Collection<Exchange> getExchanges(); - - Collection<ExchangeType<? extends Exchange>> getExchangeTypes(); - - DurableConfigurationStore getDurableConfigurationStore(); - - MessageStore getMessageStore(); - - SecurityManager getSecurityManager(); - - void addVirtualHostListener(VirtualHostListener listener); - - void close(); - - UUID getId(); - - void scheduleHouseKeepingTask(long period, HouseKeepingTask task); - - long getHouseKeepingTaskCount(); - - public long getHouseKeepingCompletedTaskCount(); - - int getHouseKeepingPoolSize(); - - void setHouseKeepingPoolSize(int newSize); - - int getHouseKeepingActiveCount(); - - VirtualHostRegistry getVirtualHostRegistry(); - - DtxRegistry getDtxRegistry(); - - LinkRegistry getLinkRegistry(String remoteContainerId); - - ScheduledFuture<?> scheduleTask(long delay, Runnable timeoutTask); - - State getState(); - - public void block(); - - public void unblock(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java deleted file mode 100755 index 39ca3197b4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java +++ /dev/null @@ -1,375 +0,0 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.qpid.server.virtualhost; - -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; -import java.util.UUID; - -import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQStoreException; -import org.apache.qpid.server.exchange.ExchangeFactory; -import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.messages.TransactionLogMessages; -import org.apache.qpid.server.logging.subjects.MessageStoreLogSubject; -import org.apache.qpid.server.message.EnqueableMessage; -import org.apache.qpid.server.message.MessageReference; -import org.apache.qpid.server.message.ServerMessage; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.QueueEntry; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.MessageStoreRecoveryHandler; -import org.apache.qpid.server.store.StoredMessage; -import org.apache.qpid.server.store.Transaction; -import org.apache.qpid.server.store.TransactionLogRecoveryHandler; -import org.apache.qpid.server.store.TransactionLogResource; -import org.apache.qpid.server.txn.DtxBranch; -import org.apache.qpid.server.txn.DtxRegistry; -import org.apache.qpid.server.txn.ServerTransaction; -import org.apache.qpid.transport.Xid; -import org.apache.qpid.transport.util.Functions; - -public class VirtualHostConfigRecoveryHandler implements - MessageStoreRecoveryHandler, - MessageStoreRecoveryHandler.StoredMessageRecoveryHandler, - TransactionLogRecoveryHandler, - TransactionLogRecoveryHandler.QueueEntryRecoveryHandler, - TransactionLogRecoveryHandler.DtxRecordRecoveryHandler -{ - private static final Logger _logger = Logger.getLogger(VirtualHostConfigRecoveryHandler.class); - - private final VirtualHost _virtualHost; - - private final Map<String, Integer> _queueRecoveries = new TreeMap<String, Integer>(); - private final Map<Long, ServerMessage> _recoveredMessages = new HashMap<Long, ServerMessage>(); - private final Map<Long, StoredMessage> _unusedMessages = new HashMap<Long, StoredMessage>(); - - private final ExchangeRegistry _exchangeRegistry; - private final ExchangeFactory _exchangeFactory; - - private MessageStoreLogSubject _logSubject; - private MessageStore _store; - - public VirtualHostConfigRecoveryHandler(VirtualHost virtualHost, - ExchangeRegistry exchangeRegistry, - ExchangeFactory exchangeFactory) - { - _virtualHost = virtualHost; - _exchangeRegistry = exchangeRegistry; - _exchangeFactory = exchangeFactory; - } - - public VirtualHostConfigRecoveryHandler begin(MessageStore store) - { - _logSubject = new MessageStoreLogSubject(_virtualHost.getName(), store.getClass().getSimpleName()); - _store = store; - CurrentActor.get().message(_logSubject, TransactionLogMessages.RECOVERY_START(null, false)); - return this; - } - - public StoredMessageRecoveryHandler begin() - { - return this; - } - - public void message(StoredMessage message) - { - ServerMessage serverMessage = message.getMetaData().getType().createMessage(message); - - _recoveredMessages.put(message.getMessageNumber(), serverMessage); - _unusedMessages.put(message.getMessageNumber(), message); - } - - public void completeMessageRecovery() - { - } - - public void dtxRecord(long format, byte[] globalId, byte[] branchId, - Transaction.Record[] enqueues, - Transaction.Record[] dequeues) - { - Xid id = new Xid(format, globalId, branchId); - DtxRegistry dtxRegistry = _virtualHost.getDtxRegistry(); - DtxBranch branch = dtxRegistry.getBranch(id); - if(branch == null) - { - branch = new DtxBranch(id, _store, _virtualHost); - dtxRegistry.registerBranch(branch); - } - for(Transaction.Record record : enqueues) - { - final AMQQueue queue = _virtualHost.getQueue(record.getQueue().getId()); - if(queue != null) - { - final long messageId = record.getMessage().getMessageNumber(); - final ServerMessage message = _recoveredMessages.get(messageId); - _unusedMessages.remove(messageId); - - if(message != null) - { - final MessageReference ref = message.newReference(); - - - branch.enqueue(queue,message); - - branch.addPostTransactionAcion(new ServerTransaction.Action() - { - - public void postCommit() - { - try - { - - queue.enqueue(message, true, null); - ref.release(); - } - catch (AMQException e) - { - _logger.error("Unable to enqueue message " + message.getMessageNumber() + " into " + - "queue " + queue.getName() + " (from XA transaction)", e); - throw new RuntimeException(e); - } - } - - public void onRollback() - { - ref.release(); - } - }); - } - else - { - StringBuilder xidString = xidAsString(id); - CurrentActor.get().message(_logSubject, - TransactionLogMessages.XA_INCOMPLETE_MESSAGE(xidString.toString(), - Long.toString(messageId))); - - } - - } - else - { - StringBuilder xidString = xidAsString(id); - CurrentActor.get().message(_logSubject, - TransactionLogMessages.XA_INCOMPLETE_QUEUE(xidString.toString(), - record.getQueue().getId().toString())); - - } - } - for(Transaction.Record record : dequeues) - { - final AMQQueue queue = _virtualHost.getQueue(record.getQueue().getId()); - if(queue != null) - { - final long messageId = record.getMessage().getMessageNumber(); - final ServerMessage message = _recoveredMessages.get(messageId); - _unusedMessages.remove(messageId); - - if(message != null) - { - final QueueEntry entry = queue.getMessageOnTheQueue(messageId); - - entry.acquire(); - - branch.dequeue(queue, message); - - branch.addPostTransactionAcion(new ServerTransaction.Action() - { - - public void postCommit() - { - entry.discard(); - } - - public void onRollback() - { - entry.release(); - } - }); - } - else - { - StringBuilder xidString = xidAsString(id); - CurrentActor.get().message(_logSubject, - TransactionLogMessages.XA_INCOMPLETE_MESSAGE(xidString.toString(), - Long.toString(messageId))); - - } - - } - else - { - StringBuilder xidString = xidAsString(id); - CurrentActor.get().message(_logSubject, - TransactionLogMessages.XA_INCOMPLETE_QUEUE(xidString.toString(), - record.getQueue().getId().toString())); - } - - } - - try - { - branch.setState(DtxBranch.State.PREPARED); - branch.prePrepareTransaction(); - } - catch (AMQStoreException e) - { - _logger.error("Unexpected database exception when attempting to prepare a recovered XA transaction " + - xidAsString(id), e); - throw new RuntimeException(e); - } - } - - private static StringBuilder xidAsString(Xid id) - { - return new StringBuilder("(") - .append(id.getFormat()) - .append(',') - .append(Functions.str(id.getGlobalId())) - .append(',') - .append(Functions.str(id.getBranchId())) - .append(')'); - } - - public void completeDtxRecordRecovery() - { - for(StoredMessage m : _unusedMessages.values()) - { - _logger.warn("Message id " + m.getMessageNumber() + " in store, but not in any queue - removing...."); - m.remove(); - } - CurrentActor.get().message(_logSubject, TransactionLogMessages.RECOVERY_COMPLETE(null, false)); - } - - public void complete() - { - } - - public void queueEntry(final UUID queueId, long messageId) - { - AMQQueue queue = _virtualHost.getQueue(queueId); - try - { - if(queue != null) - { - String queueName = queue.getName(); - ServerMessage message = _recoveredMessages.get(messageId); - _unusedMessages.remove(messageId); - - if(message != null) - { - - - if (_logger.isDebugEnabled()) - { - _logger.debug("On recovery, delivering " + message.getMessageNumber() + " to " + queueName); - } - - Integer count = _queueRecoveries.get(queueName); - if (count == null) - { - count = 0; - } - - queue.enqueue(message); - - _queueRecoveries.put(queueName, ++count); - } - else - { - _logger.warn("Message id " + messageId + " referenced in log as enqueued in queue " + queueName + " is unknown, entry will be discarded"); - Transaction txn = _store.newTransaction(); - txn.dequeueMessage(queue, new DummyMessage(messageId)); - txn.commitTranAsync(); - } - } - else - { - _logger.warn("Message id " + messageId + " in log references queue with id " + queueId + " which is not in the configuration, entry will be discarded"); - Transaction txn = _store.newTransaction(); - TransactionLogResource mockQueue = - new TransactionLogResource() - { - @Override - public UUID getId() - { - return queueId; - } - }; - txn.dequeueMessage(mockQueue, new DummyMessage(messageId)); - txn.commitTranAsync(); - } - - } - catch(AMQException e) - { - throw new RuntimeException(e); - } - } - - public DtxRecordRecoveryHandler completeQueueEntryRecovery() - { - - for(Map.Entry<String,Integer> entry : _queueRecoveries.entrySet()) - { - CurrentActor.get().message(_logSubject, TransactionLogMessages.RECOVERED(entry.getValue(), entry.getKey())); - - CurrentActor.get().message(_logSubject, TransactionLogMessages.RECOVERY_COMPLETE(entry.getKey(), true)); - } - - - - return this; - } - - private static class DummyMessage implements EnqueableMessage - { - - - private final long _messageId; - - public DummyMessage(long messageId) - { - _messageId = messageId; - } - - public long getMessageNumber() - { - return _messageId; - } - - - public boolean isPersistent() - { - return true; - } - - - public StoredMessage getStoredMessage() - { - return null; - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostFactoryRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostFactoryRegistry.java deleted file mode 100644 index 626615a59f..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostFactoryRegistry.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.apache.qpid.server.virtualhost;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import org.apache.qpid.server.plugin.QpidServiceLoader; -import org.apache.qpid.server.plugin.VirtualHostFactory; - -public class VirtualHostFactoryRegistry -{ - private static Map<String, VirtualHostFactory> getFactoryMap() - { - Map<String, VirtualHostFactory> virtualHostFactories = new HashMap<String, VirtualHostFactory>(); - QpidServiceLoader<VirtualHostFactory> qpidServiceLoader = new QpidServiceLoader<VirtualHostFactory>(); - Iterable<VirtualHostFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(VirtualHostFactory.class); - for (VirtualHostFactory virtualHostFactory : factories) - { - String type = virtualHostFactory.getType(); - VirtualHostFactory factory = virtualHostFactories.put(type, virtualHostFactory); - if (factory != null) - { - throw new IllegalStateException("VirtualHostFactory with type name '" + type - + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '" - + virtualHostFactory.getClass().getName() + "'"); - } - } - return virtualHostFactories; - } - - - public static Collection<VirtualHostFactory> getFactories() - { - return Collections.unmodifiableCollection(getFactoryMap().values()); - } - - public static Collection<String> getVirtualHostTypes() - { - return Collections.unmodifiableCollection(getFactoryMap().keySet()); - } - - public static VirtualHostFactory getFactory(String type) - { - return getFactoryMap().get(type); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostListener.java deleted file mode 100644 index 8527435eea..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.protocol.AMQConnectionModel; -import org.apache.qpid.server.queue.AMQQueue; - -public interface VirtualHostListener -{ - - public void queueRegistered(AMQQueue queue); - - public void queueUnregistered(AMQQueue queue); - - public void connectionRegistered(AMQConnectionModel connection); - - public void connectionUnregistered(AMQConnectionModel connection); - - public void exchangeRegistered(Exchange exchange); - - public void exchangeUnregistered(Exchange exchange); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java deleted file mode 100644 index 483e11942b..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost; - -import org.apache.qpid.common.Closeable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - - -public class VirtualHostRegistry implements Closeable -{ - private final Map<String, VirtualHost> _registry = new ConcurrentHashMap<String, VirtualHost>(); - private String _defaultVirtualHostName; - - - public VirtualHostRegistry() - { - super(); - } - - public synchronized void registerVirtualHost(VirtualHost host) - { - if(_registry.containsKey(host.getName())) - { - throw new IllegalArgumentException("Virtual Host with name " + host.getName() + " already registered."); - } - _registry.put(host.getName(),host); - } - - public synchronized void unregisterVirtualHost(VirtualHost host) - { - _registry.remove(host.getName()); - } - - public VirtualHost getVirtualHost(String name) - { - if(name == null || name.trim().length() == 0 || "/".equals(name.trim())) - { - name = getDefaultVirtualHostName(); - } - - return _registry.get(name); - } - - public VirtualHost getDefaultVirtualHost() - { - return getVirtualHost(getDefaultVirtualHostName()); - } - - private String getDefaultVirtualHostName() - { - return _defaultVirtualHostName; - } - - public void setDefaultVirtualHostName(String defaultVirtualHostName) - { - _defaultVirtualHostName = defaultVirtualHostName; - } - - - public Collection<VirtualHost> getVirtualHosts() - { - return new ArrayList<VirtualHost>(_registry.values()); - } - - public void close() - { - for (VirtualHost virtualHost : getVirtualHosts()) - { - virtualHost.close(); - } - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/QueueExistsException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/QueueExistsException.java deleted file mode 100644 index 54f7d0d172..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/QueueExistsException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.server.virtualhost.plugins; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.queue.AMQQueue; - -public class QueueExistsException extends AMQException -{ - private final AMQQueue _existing; - - public QueueExistsException(String name, AMQQueue existing) - { - super(name); - _existing = existing; - } - - public AMQQueue getExistingQueue() - { - return _existing; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/tools/security/Passwd.java b/qpid/java/broker/src/main/java/org/apache/qpid/tools/security/Passwd.java deleted file mode 100644 index cd833c89c4..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/tools/security/Passwd.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.qpid.tools.security; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; -import java.security.DigestException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import org.apache.commons.codec.binary.Base64; - -/** - * Utility to generate user:encodedPassword string for use in md5passwd - */ -public class Passwd -{ - public static void main(String args[]) throws NoSuchAlgorithmException, DigestException, IOException - { - if (args.length != 2) - { - System.out.println("Passwd <username> <password>"); - System.exit(0); - } - - Passwd passwd = new Passwd(); - String output = passwd.getOutput(args[0], args[1]); - System.out.println(output); - } - - public String getOutput(String userName, String password) throws UnsupportedEncodingException, NoSuchAlgorithmException - { - byte[] data = password.getBytes("utf-8"); - - MessageDigest md = MessageDigest.getInstance("MD5"); - - for (byte b : data) - { - md.update(b); - } - - byte[] digest = md.digest(); - - Base64 b64 = new Base64(); - - byte[] encoded = b64.encode(digest); - - String encodedStr = new String(encoded, Charset.forName("utf-8")); - return userName + ":" + encodedStr; - } -} diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory deleted file mode 100644 index 8ff67030ef..0000000000 --- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory -org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory -org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManagerFactory -org.apache.qpid.server.security.auth.manager.KerberosAuthenticationManagerFactory -org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory -org.apache.qpid.server.security.auth.manager.SimpleLDAPAuthenticationManagerFactory diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfigurationStoreFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfigurationStoreFactory deleted file mode 100644 index cd314abcae..0000000000 --- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfigurationStoreFactory +++ /dev/null @@ -1,20 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -org.apache.qpid.server.configuration.store.factory.JsonConfigurationStoreFactory -org.apache.qpid.server.configuration.store.factory.MemoryConfigurationStoreFactory diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.DurableConfigurationStoreFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.DurableConfigurationStoreFactory deleted file mode 100644 index d183d91f18..0000000000 --- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.DurableConfigurationStoreFactory +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -org.apache.qpid.server.store.JsonFileConfigStoreFactory diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType deleted file mode 100644 index 4ad646b7a0..0000000000 --- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType +++ /dev/null @@ -1,22 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -org.apache.qpid.server.exchange.DirectExchangeType -org.apache.qpid.server.exchange.TopicExchangeType -org.apache.qpid.server.exchange.FanoutExchangeType -org.apache.qpid.server.exchange.HeadersExchangeType diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory deleted file mode 100644 index 6bfb55ff18..0000000000 --- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -org.apache.qpid.server.security.group.FileGroupManagerFactory diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.JDBCConnectionProviderFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.JDBCConnectionProviderFactory deleted file mode 100644 index e0ae6e97cc..0000000000 --- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.JDBCConnectionProviderFactory +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -org.apache.qpid.server.store.jdbc.DefaultConnectionProviderFactory diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PreferencesProviderFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PreferencesProviderFactory deleted file mode 100644 index 9fe8379120..0000000000 --- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PreferencesProviderFactory +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -org.apache.qpid.server.model.adapter.FileSystemPreferencesProviderFactory
\ No newline at end of file diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.VirtualHostFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.VirtualHostFactory deleted file mode 100644 index 81217884e4..0000000000 --- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.VirtualHostFactory +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# -org.apache.qpid.server.virtualhost.StandardVirtualHostFactory diff --git a/qpid/java/broker/src/main/resources/initial-config.json b/qpid/java/broker/src/main/resources/initial-config.json deleted file mode 100644 index a203190c4b..0000000000 --- a/qpid/java/broker/src/main/resources/initial-config.json +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ -{ - "name": "Broker", - "storeVersion": 1, - "modelVersion": "1.1", - "defaultVirtualHost" : "default", - "authenticationproviders" : [ { - "name" : "passwordFile", - "type" : "PlainPasswordFile", - "path" : "${qpid.home_dir}/etc/passwd", - "preferencesproviders" : [{ - "name": "fileSystemPreferences", - "type": "FileSystemPreferences", - "path" : "${qpid.work_dir}/preferences/passwordFile" - }] - } ], - "ports" : [ { - "name" : "AMQP", - "port" : "${qpid.amqp_port}", - "authenticationProvider" : "passwordFile" - }, { - "name" : "HTTP", - "port" : "${qpid.http_port}", - "authenticationProvider" : "passwordFile", - "protocols" : [ "HTTP" ] - }, { - "name" : "RMI_REGISTRY", - "port" : "${qpid.rmi_port}", - "protocols" : [ "RMI" ] - }, { - "name" : "JMX_CONNECTOR", - "port" : "${qpid.jmx_port}", - "authenticationProvider" : "passwordFile", - "protocols" : [ "JMX_RMI" ] - }], - "virtualhosts" : [ { - "name" : "default", - "type" : "STANDARD", - "storeType" : "DERBY", - "storePath" : "${qpid.work_dir}/derbystore/default" - } ], - "plugins" : [ { - "pluginType" : "MANAGEMENT-HTTP", - "name" : "httpManagement" - }, { - "pluginType" : "MANAGEMENT-JMX", - "name" : "jmxManagement" - } ] -} |
