Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
BZ-1206627, BZ-1198662: improvements on shutdown (now with priority f…
Browse files Browse the repository at this point in the history
…eture of shutdown services) and additional improvements on git and cluster lock mechanism
  • Loading branch information
porcelli authored and manstis committed Apr 9, 2015
1 parent c670d9f commit f55557b
Show file tree
Hide file tree
Showing 29 changed files with 410 additions and 346 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.uberfire.backend.vfs;

import org.uberfire.commons.lifecycle.Disposable;
import org.uberfire.mvp.Command;
import org.uberfire.mvp.ParameterizedCommand;
import org.uberfire.rpc.SessionInfo;

public interface ObservablePath extends Path {
public interface ObservablePath extends Path,
Disposable {

void onRename( final Command command );

Expand All @@ -22,8 +24,6 @@ public interface ObservablePath extends Path {

void onConcurrentCopy( final ParameterizedCommand<OnConcurrentCopyEvent> command );

void dispose();

ObservablePath wrap( final Path path );

public interface OnConcurrentUpdateEvent extends SessionInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ public IOService create( CreationalContext<IOService> ctx ) {
@Override
public void destroy( final IOService instance,
final CreationalContext<IOService> ctx ) {
instance.dispose();
ctx.release();
}
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.uberfire.backend.server.cluster;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Produces;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.uberfire.commons.cluster.ClusterService;
import org.uberfire.commons.cluster.ClusterServiceFactory;
import org.uberfire.commons.services.cdi.ApplicationStarted;
import org.uberfire.commons.services.cdi.Startup;
import org.uberfire.commons.services.cdi.StartupType;

@ApplicationScoped
@Startup(StartupType.BOOTSTRAP)
public class ClusterServiceFactoryProducer {

private static final Logger logger = LoggerFactory.getLogger( ClusterServiceFactoryProducer.class );
Expand All @@ -28,12 +29,4 @@ public class ClusterServiceFactoryProducer {
public ClusterServiceFactory clusterServiceFactory() {
return factory;
}

public void startOnEvent( @Observes ApplicationStarted event ) {
logger.debug( "Received event for application started {}", clusterService );
if ( factory != null && factory instanceof ClusterServiceFactorySimpleImpl ) {
logger.debug( "About to create cluster service..." );
( (ClusterServiceFactorySimpleImpl) factory ).startClusterService();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public ClusterServiceFactorySimpleImpl( final String clusterName,
public ClusterService build( final MessageHandlerResolver resolver ) {
if ( clusterService == null ) {
clusterService = new ClusterServiceHelix( clusterName, zkAddress, localId, resourceName, resolver );
if ( autostart ) {
clusterService.start();
}
} else {
clusterService.addMessageHandlerResolver( resolver );
}
Expand All @@ -47,9 +44,4 @@ public boolean isAutoStart() {
return autostart;
}

public void startClusterService() {
if ( clusterService != null ) {
clusterService.start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import org.uberfire.backend.server.security.IOSecurityAuth;
import org.uberfire.commons.cluster.ClusterServiceFactory;
import org.uberfire.commons.services.cdi.Startup;
import org.uberfire.commons.services.cdi.StartupType;
import org.uberfire.io.IOService;
import org.uberfire.io.impl.IOServiceNio2WrapperImpl;
import org.uberfire.io.impl.cluster.IOServiceClusterImpl;

@ApplicationScoped
@Startup
@Startup(StartupType.BOOTSTRAP)
public class ConfigIOServiceProducer {

@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.uberfire.backend.server.io;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import javax.annotation.PostConstruct;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.uberfire.commons.async.SimpleAsyncExecutorService;
import org.uberfire.commons.cluster.ClusterService;
import org.uberfire.commons.cluster.ClusterServiceFactory;
import org.uberfire.commons.lifecycle.Disposable;
import org.uberfire.commons.lifecycle.PriorityDisposable;
import org.uberfire.java.nio.file.api.FileSystemProviders;
import org.uberfire.java.nio.file.spi.FileSystemProvider;

public class DisposableShutdownService implements ServletContextListener {

@Inject
private Instance<PriorityDisposable> disposables;

@Inject
@Named("clusterServiceFactory")
private ClusterServiceFactory clusterServiceFactory;

private ClusterService clusterService = null;

@PostConstruct
public void init() {
if ( clusterServiceFactory != null ) {
//TODO: hack that should be changed soon;
clusterService = clusterServiceFactory.build( null );
}
}

@Override
public void contextInitialized( ServletContextEvent sce ) {

}

@Override
public void contextDestroyed( final ServletContextEvent sce ) {
final ArrayList<PriorityDisposable> collection = new ArrayList<PriorityDisposable>();
for ( final PriorityDisposable disposable : disposables ) {
collection.add( disposable );
}

Collections.sort( collection, new Comparator<PriorityDisposable>() {
@Override
public int compare( final PriorityDisposable o1,
final PriorityDisposable o2 ) {
return ( o2.priority() < o1.priority() ) ? -1 : ( ( o2.priority() == o1.priority() ) ? 0 : 1 );
}
} );

if ( clusterService != null ) {
clusterService.lock();
}

for ( final PriorityDisposable disposable : collection ) {
disposable.dispose();
}

SimpleAsyncExecutorService.shutdownInstances();

for ( final FileSystemProvider fileSystemProvider : FileSystemProviders.installedProviders() ) {
if ( fileSystemProvider instanceof Disposable ) {
( (Disposable) fileSystemProvider ).dispose();
}
}

if ( clusterService != null ) {
clusterService.unlock();
clusterService.dispose();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package org.uberfire.commons.cluster;

import org.uberfire.commons.lifecycle.PriorityDisposable;
import org.uberfire.commons.lock.LockService;
import org.uberfire.commons.message.MessageHandlerResolver;
import org.uberfire.commons.message.MessageService;

public interface ClusterService extends MessageService,
LockService {
LockService,
PriorityDisposable {

void addMessageHandlerResolver( final MessageHandlerResolver resolver );

void start();

void dispose();

void onStart( Runnable runnable );

boolean isInnerLocked();
int getHoldCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

public interface Disposable {

public void dispose();
void dispose();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2014 JBoss, by Red Hat, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.uberfire.commons.lifecycle;

public interface PriorityDisposable extends Disposable {

int priority();

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.uberfire.commons.lock;

public abstract interface LockService {
public interface LockService {

void lock();

void unlock();

boolean isLocked();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<module>

<source path='data'/>
<source path='lifecycle'/>

<source path='validation'>
<exclude name='Preconditions.java'/>
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions uberfire-io/src/main/java/org/uberfire/io/IOService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Map;
import java.util.Set;

import org.uberfire.commons.lifecycle.Disposable;
import org.uberfire.commons.lifecycle.PriorityDisposable;
import org.uberfire.java.nio.IOException;
import org.uberfire.java.nio.channels.SeekableByteChannel;
import org.uberfire.java.nio.file.AtomicMoveNotSupportedException;
Expand All @@ -51,12 +53,10 @@
/**
*
*/
public interface IOService {
public interface IOService extends PriorityDisposable {

public static Set<OpenOption> EMPTY_OPTIONS = new HashSet<OpenOption>();

void dispose();

void startBatch( final FileSystem fs );

void startBatch( final FileSystem[] fs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@

import static org.uberfire.java.nio.file.StandardOpenOption.*;

public abstract class AbstractIOService implements IOServiceIdentifiable {
public abstract class AbstractIOService implements IOServiceIdentifiable,
IOServiceLockable {

private static final Logger logger = LoggerFactory.getLogger( AbstractIOService.class );

Expand Down Expand Up @@ -172,6 +173,11 @@ public void endBatch() {
batchLockControl.unlock();
}

@Override
public BatchLockControl getLockControl() {
return batchLockControl;
}

private void cleanupClosedFileSystems() {
final ArrayList<FileSystem> removeList = new ArrayList<FileSystem>();
for ( final FileSystem fileSystem : fileSystems ) {
Expand Down

0 comments on commit f55557b

Please sign in to comment.