001/* 002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bdelbosc 018 */ 019package org.nuxeo.ecm.platform.importer.mqueues.mqueues; 020 021 022import java.io.Externalizable; 023import java.util.Collection; 024 025/** 026 * Manage MQueue and give access to appender and tailers. 027 * 028 * @since 9.2 029 */ 030public interface MQManager<M extends Externalizable> extends AutoCloseable { 031 032 /** 033 * Returns {@code true} if a MQueue with this {@code name} exists. 034 */ 035 boolean exists(String name); 036 037 /** 038 * Creates a new MQueue with {@code size} partitions if the MQueue does not exists. 039 * Returns true it the MQueue has been created. 040 */ 041 boolean createIfNotExists(String name, int size); 042 043 /** 044 * Try to delete a MQueue. 045 * Returns true if successfully deleted, might not be possible depending on the implementation. 046 */ 047 boolean delete(String name); 048 049 /** 050 * Get an appender for the MQueue named {@code name}. 051 * An appender is thread safe. 052 */ 053 MQAppender<M> getAppender(String name); 054 055 /** 056 * Create a tailer for a consumer {@code group} and assign a single {@code partition}. 057 * A tailer is NOT thread safe. 058 */ 059 MQTailer<M> createTailer(String group, MQPartition partition); 060 061 /** 062 * Create a tailer for a consumer {@code group} and assign multiple {@code partitions}. 063 * A tailer is NOT thread safe. 064 */ 065 MQTailer<M> createTailer(String group, Collection<MQPartition> partitions); 066 067 /** 068 * Returns {@code true} if the MQueue {@link #subscribe} method is supported. 069 */ 070 boolean supportSubscribe(); 071 072 /** 073 * Create a tailer for a consumer {@code group} and subscribe to multiple MQueues. 074 * The partitions assignment is done dynamically depending on the number of subscribers. 075 * The partitions can change during tailers life, this is called a rebalancing. 076 * A listener can be used to be notified on assignment changes. 077 * <p/> 078 * A tailer is NOT thread safe. 079 * <p/> 080 * You should not mix {@link #createTailer} and {@code subscribe} usage using the same {@code group}. 081 */ 082 MQTailer<M> subscribe(String group, Collection<String> names, MQRebalanceListener listener); 083 084}