Search in sources :

Example 11 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.

the class ConnectionImpl method reconnectAndWait.

private void reconnectAndWait() {
    if (reconnector.isDebug())
        System.out.println(new Date() + " " + toString() + ": initiate reconnect and wait ...");
    lastConnectionLost = System.currentTimeMillis();
    Semaphore sem = new Semaphore();
    POReconnect po = new POReconnect(sem, this);
    connector.dispatch(po);
    sem.waitHere();
    if (reconnector.isDebug())
        System.out.println(new Date() + " " + toString() + ": reconnect done, connection =" + connection);
}
Also used : POReconnect(com.swiftmq.jms.v750.po.POReconnect) Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 12 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.

the class Connector method close.

public void close() {
    if (debug)
        System.out.println(toString() + ", close ...");
    synchronized (closeSync) {
        if (closeInProgress) {
            if (debug)
                System.out.println(toString() + ", close in progress, return");
            return;
        }
        closeInProgress = true;
    }
    Semaphore sem = new Semaphore();
    dispatch(new POClose(sem));
    sem.waitHere();
    if (debug)
        System.out.println(toString() + ", close done");
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 13 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.

the class MessageConsumerImpl method close.

public void close() throws JMSException {
    if (closed)
        return;
    if (!mySession.isSessionStarted()) {
        close(null);
        return;
    }
    CloseConsumer request = new CloseConsumer(consumerId);
    request._sem = new Semaphore();
    mySession.serviceRequest(request);
    request._sem.waitHere();
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 14 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.

the class SessionImpl method close.

public void close() throws JMSException {
    if (closed)
        return;
    if (messageListener == null && !isSessionStarted()) {
        _close();
        return;
    }
    CloseSession request = new CloseSession();
    request._sem = new Semaphore();
    if (messageListener == null)
        serviceRequest(request);
    else {
        addMessageChunk(request);
    }
    request._sem.waitHere(5000);
    if (!request._sem.isNotified())
        _close();
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 15 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class StoreSwiftletImpl method startup.

protected void startup(Configuration config) throws SwiftletException {
    try {
        ctx = new StoreContext(this, config);
        ctx.swapFileFactory = createSwapFileFactory();
        ctx.swapPath = SwiftUtilities.addWorkingDir((String) ctx.swapEntity.getProperty("path").getValue());
        swapMaxLength = ((Long) ctx.swapEntity.getProperty("roll-over-size").getValue()).longValue();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", "startup...");
        ctx.durableStore = createDurableSubscriberStore(ctx, SwiftUtilities.addWorkingDir((String) ctx.durableEntity.getProperty("path").getValue()));
        deleteSwaps();
        ctx.recoveryManager = new RecoveryManager(ctx);
        ctx.stableStore = createStableStore(ctx, SwiftUtilities.addWorkingDir((String) ctx.dbEntity.getProperty("path").getValue()), ((Integer) ctx.dbEntity.getProperty("initial-page-size").getValue()).intValue());
        Property minCacheSizeProp = ctx.cacheEntity.getProperty("min-size");
        Property maxCacheSizeProp = ctx.cacheEntity.getProperty("max-size");
        int minCacheSize = ((Integer) minCacheSizeProp.getValue()).intValue();
        int maxCacheSize = ((Integer) maxCacheSizeProp.getValue()).intValue();
        if (minCacheSize > maxCacheSize)
            throw new Exception("Cache/min-size is invalid, must be less than max-size!");
        minCacheSizeProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                int n = ((Integer) newValue).intValue();
                if (n > ((Integer) ctx.cacheEntity.getProperty("max-size").getValue()).intValue())
                    throw new PropertyChangeException("min-size is invalid, must be less than max-size!");
            }
        });
        maxCacheSizeProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                int n = ((Integer) newValue).intValue();
                if (n < ((Integer) ctx.cacheEntity.getProperty("min-size").getValue()).intValue())
                    throw new PropertyChangeException("max-size is invalid, must be greater than min-size!");
            }
        });
        // ctx.preparedLog = new PreparedLogFile(ctx, SwiftUtilities.addWorkingDir((String) ctx.xaEntity.getProperty("path").getValue()),
        // ((Boolean) ctx.xaEntity.getProperty("force-sync").getValue()).booleanValue());
        ctx.cacheManager = new CacheManager(ctx, ctx.stableStore, minCacheSize, maxCacheSize);
        ctx.transactionManager = new TransactionManager(ctx);
        ctx.logManager = createLogManagerFactory().createLogManager(ctx, ctx.transactionManager, SwiftUtilities.addWorkingDir((String) ctx.txEntity.getProperty("path").getValue()), ((Long) ctx.txEntity.getProperty("checkpoint-size").getValue()).longValue(), ((Boolean) ctx.txEntity.getProperty("force-sync").getValue()).booleanValue());
        ctx.recoveryManager.restart(isRecoverOnStartup());
        rootIndex = new RootIndex(ctx, 0);
        ctx.preparedLog = new PreparedLogQueue(ctx, rootIndex.getQueueIndex(PREPARED_LOG_QUEUE));
        ctx.backupProcessor = new BackupProcessor(ctx);
        checkBackupPath();
        ctx.shrinkProcessor = new ShrinkProcessor(ctx);
        CommandRegistry commandRegistry = ctx.dbEntity.getCommandRegistry();
        CommandExecutor shrinkExecutor = new CommandExecutor() {

            public String[] execute(String[] context, Entity entity, String[] cmd) {
                if (cmd.length != 1)
                    return new String[] { TreeCommands.ERROR, "Invalid command, please try 'shrink'" };
                Semaphore sem = new Semaphore();
                StartShrink po = new StartShrink(sem);
                ctx.shrinkProcessor.enqueue(po);
                sem.waitHere();
                String[] result = null;
                if (po.isSuccess())
                    result = new String[] { TreeCommands.INFO, "Shrink initiated." };
                else
                    result = new String[] { TreeCommands.ERROR, po.getException() };
                return result;
            }
        };
        Command backupCommand = new Command("shrink", "shrink", "Perform Shrink Now", true, shrinkExecutor, true, false);
        commandRegistry.addCommand(backupCommand);
        SwiftletManager.getInstance().addSwiftletManagerListener("sys$scheduler", new SwiftletManagerAdapter() {

            public void swiftletStarted(SwiftletManagerEvent event) {
                ctx.schedulerSwiftlet = (SchedulerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$scheduler");
                jobRegistrar = new JobRegistrar(ctx);
                jobRegistrar.register();
            }

            public void swiftletStopInitiated(SwiftletManagerEvent event) {
                jobRegistrar.unregister();
            }
        });
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", "startup...done");
    } catch (Exception e) {
        e.printStackTrace();
        throw new SwiftletException(e.getMessage());
    }
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore) BackupProcessor(com.swiftmq.impl.store.standard.backup.BackupProcessor) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) SchedulerSwiftlet(com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet) CacheManager(com.swiftmq.impl.store.standard.cache.CacheManager) JobRegistrar(com.swiftmq.impl.store.standard.jobs.JobRegistrar) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) StartShrink(com.swiftmq.impl.store.standard.cache.po.StartShrink) RecoveryManager(com.swiftmq.impl.store.standard.recover.RecoveryManager) ShrinkProcessor(com.swiftmq.impl.store.standard.cache.ShrinkProcessor) SwiftletException(com.swiftmq.swiftlet.SwiftletException) TransactionManager(com.swiftmq.impl.store.standard.transaction.TransactionManager) RootIndex(com.swiftmq.impl.store.standard.index.RootIndex) PreparedLogQueue(com.swiftmq.impl.store.standard.xa.PreparedLogQueue)

Aggregations

Semaphore (com.swiftmq.tools.concurrent.Semaphore)149 MsgNoVerifier (jms.base.MsgNoVerifier)18 IOException (java.io.IOException)8 SwiftletException (com.swiftmq.swiftlet.SwiftletException)6 ArrayList (java.util.ArrayList)6 CommitLogRecord (com.swiftmq.impl.store.standard.log.CommitLogRecord)5 DataStreamOutputStream (com.swiftmq.tools.util.DataStreamOutputStream)5 List (java.util.List)5 StartBackup (com.swiftmq.impl.store.standard.backup.po.StartBackup)2 StartShrink (com.swiftmq.impl.store.standard.cache.po.StartShrink)2 UnknownHostException (java.net.UnknownHostException)2 POAttachDurableConsumer (com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer)1 POAuthenticate (com.swiftmq.amqp.v100.client.po.POAuthenticate)1 POCloseLink (com.swiftmq.amqp.v100.client.po.POCloseLink)1 POOpen (com.swiftmq.amqp.v100.client.po.POOpen)1 POProtocolRequest (com.swiftmq.amqp.v100.client.po.POProtocolRequest)1 POSendClose (com.swiftmq.amqp.v100.client.po.POSendClose)1 POSendMessage (com.swiftmq.amqp.v100.client.po.POSendMessage)1 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 Header (com.swiftmq.amqp.v100.generated.messaging.message_format.Header)1