IDEMPIERE-3043 by synchronized. sometime, get list service will wrong
This commit is contained in:
parent
f26db68e2b
commit
f2ca30d27b
|
@ -19,10 +19,12 @@ import org.compiere.util.AdempiereSystemError;
|
|||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkEvent;
|
||||
import org.osgi.framework.FrameworkListener;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
||||
public class AdempiereActivator extends AbstractActivator {
|
||||
public class AdempiereActivator extends AbstractActivator implements FrameworkListener {
|
||||
|
||||
protected final static CLogger logger = CLogger.getCLogger(AdempiereActivator.class.getName());
|
||||
|
||||
|
@ -30,6 +32,7 @@ public class AdempiereActivator extends AbstractActivator {
|
|||
public void start(BundleContext context) throws Exception {
|
||||
this.context = context;
|
||||
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
|
||||
context.addFrameworkListener(this);
|
||||
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
|
||||
serviceTracker.open();
|
||||
start();
|
||||
|
@ -146,6 +149,7 @@ public class AdempiereActivator extends AbstractActivator {
|
|||
public void stop(BundleContext context) throws Exception {
|
||||
stop();
|
||||
serviceTracker.close();
|
||||
context.removeFrameworkListener(this);
|
||||
this.context = null;
|
||||
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
|
||||
+ context.getBundle().getHeaders().get("Bundle-Version")
|
||||
|
@ -165,41 +169,6 @@ public class AdempiereActivator extends AbstractActivator {
|
|||
public IDictionaryService addingService(
|
||||
ServiceReference<IDictionaryService> reference) {
|
||||
service = context.getService(reference);
|
||||
if (Adempiere.getThreadPoolExecutor() != null) {
|
||||
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(AdempiereActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Adempiere.addServerStateChangeListener(new ServerStateChangeListener() {
|
||||
@Override
|
||||
public void stateChange(ServerStateChangeEvent event) {
|
||||
if (event.getEventType() == ServerStateChangeEvent.SERVER_START && service != null) {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(AdempiereActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -218,4 +187,51 @@ public class AdempiereActivator extends AbstractActivator {
|
|||
serverContext.setProperty("#AD_Client_ID", "0");
|
||||
ServerContext.setCurrentInstance(serverContext);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void frameworkEvent(FrameworkEvent event) {
|
||||
if (event.getType() == FrameworkEvent.STARTED) {
|
||||
frameworkStarted();
|
||||
}
|
||||
}
|
||||
|
||||
private void frameworkStarted() {
|
||||
if (service != null) {
|
||||
if (Adempiere.getThreadPoolExecutor() != null) {
|
||||
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(AdempiereActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Adempiere.addServerStateChangeListener(new ServerStateChangeListener() {
|
||||
@Override
|
||||
public void stateChange(ServerStateChangeEvent event) {
|
||||
if (event.getEventType() == ServerStateChangeEvent.SERVER_START && service != null) {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(AdempiereActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ import org.compiere.util.CLogger;
|
|||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Trx;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkEvent;
|
||||
import org.osgi.framework.FrameworkListener;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
||||
|
@ -46,7 +48,7 @@ import org.osgi.util.tracker.ServiceTracker;
|
|||
* @author hengsin
|
||||
*
|
||||
*/
|
||||
public class Incremental2PackActivator extends AbstractActivator {
|
||||
public class Incremental2PackActivator extends AbstractActivator implements FrameworkListener {
|
||||
|
||||
protected final static CLogger logger = CLogger.getCLogger(Incremental2PackActivator.class.getName());
|
||||
|
||||
|
@ -54,6 +56,7 @@ public class Incremental2PackActivator extends AbstractActivator {
|
|||
public void start(BundleContext context) throws Exception {
|
||||
this.context = context;
|
||||
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
|
||||
context.addFrameworkListener(this);
|
||||
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
|
||||
serviceTracker.open();
|
||||
start();
|
||||
|
@ -265,6 +268,7 @@ public class Incremental2PackActivator extends AbstractActivator {
|
|||
public void stop(BundleContext context) throws Exception {
|
||||
stop();
|
||||
serviceTracker.close();
|
||||
context.removeFrameworkListener(this);
|
||||
this.context = null;
|
||||
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
|
||||
+ context.getBundle().getHeaders().get("Bundle-Version")
|
||||
|
@ -290,41 +294,6 @@ public class Incremental2PackActivator extends AbstractActivator {
|
|||
public IDictionaryService addingService(
|
||||
ServiceReference<IDictionaryService> reference) {
|
||||
service = context.getService(reference);
|
||||
if (Adempiere.getThreadPoolExecutor() != null) {
|
||||
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(Incremental2PackActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Adempiere.addServerStateChangeListener(new ServerStateChangeListener() {
|
||||
@Override
|
||||
public void stateChange(ServerStateChangeEvent event) {
|
||||
if (event.getEventType() == ServerStateChangeEvent.SERVER_START && service != null) {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(Incremental2PackActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -343,4 +312,51 @@ public class Incremental2PackActivator extends AbstractActivator {
|
|||
serverContext.setProperty("#AD_Client_ID", "0");
|
||||
ServerContext.setCurrentInstance(serverContext);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void frameworkEvent(FrameworkEvent event) {
|
||||
if (event.getType() == FrameworkEvent.STARTED) {
|
||||
frameworkStarted();
|
||||
}
|
||||
}
|
||||
|
||||
private void frameworkStarted() {
|
||||
if (service != null) {
|
||||
if (Adempiere.getThreadPoolExecutor() != null) {
|
||||
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(Incremental2PackActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Adempiere.addServerStateChangeListener(new ServerStateChangeListener() {
|
||||
@Override
|
||||
public void stateChange(ServerStateChangeEvent event) {
|
||||
if (event.getEventType() == ServerStateChangeEvent.SERVER_START && service != null) {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(Incremental2PackActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,12 @@ import org.compiere.util.CLogger;
|
|||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Util;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkEvent;
|
||||
import org.osgi.framework.FrameworkListener;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
||||
public class PackInApplicationActivator extends AbstractActivator {
|
||||
public class PackInApplicationActivator extends AbstractActivator implements FrameworkListener {
|
||||
|
||||
protected final static CLogger logger = CLogger.getCLogger(PackInApplicationActivator.class.getName());
|
||||
private List<File> filesToProcess = new ArrayList<>();
|
||||
|
@ -55,6 +57,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
|||
public void start(BundleContext context) throws Exception {
|
||||
this.context = context;
|
||||
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " starting...");
|
||||
context.addFrameworkListener(this);
|
||||
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
|
||||
serviceTracker.open();
|
||||
start();
|
||||
|
@ -78,6 +81,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
|||
public void stop(BundleContext context) throws Exception {
|
||||
stop();
|
||||
serviceTracker.close();
|
||||
context.removeFrameworkListener(this);
|
||||
this.context = null;
|
||||
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
|
||||
+ context.getBundle().getHeaders().get("Bundle-Version")
|
||||
|
@ -87,27 +91,6 @@ public class PackInApplicationActivator extends AbstractActivator {
|
|||
@Override
|
||||
public IDictionaryService addingService(ServiceReference<IDictionaryService> reference) {
|
||||
service = context.getService(reference);
|
||||
if (Adempiere.getThreadPoolExecutor() != null) {
|
||||
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int timeout = MSysConfig.getIntValue(MSysConfig.AUTOMATIC_PACKIN_INITIAL_DELAY, 120) * 1000;
|
||||
String folders = MSysConfig.getValue(MSysConfig.AUTOMATIC_PACKIN_FOLDERS);
|
||||
automaticPackin(timeout, folders, true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Adempiere.addServerStateChangeListener(new ServerStateChangeListener() {
|
||||
@Override
|
||||
public void stateChange(ServerStateChangeEvent event) {
|
||||
if (event.getEventType() == ServerStateChangeEvent.SERVER_START && service != null) {
|
||||
int timeout = MSysConfig.getIntValue(MSysConfig.AUTOMATIC_PACKIN_INITIAL_DELAY, 120) * 1000;
|
||||
String folders = MSysConfig.getValue(MSysConfig.AUTOMATIC_PACKIN_FOLDERS);
|
||||
automaticPackin(timeout, folders, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -411,4 +394,37 @@ public class PackInApplicationActivator extends AbstractActivator {
|
|||
ServerContext.setCurrentInstance(serverContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void frameworkEvent(FrameworkEvent event) {
|
||||
if (event.getType() == FrameworkEvent.STARTED) {
|
||||
frameworkStarted();
|
||||
}
|
||||
}
|
||||
|
||||
private void frameworkStarted() {
|
||||
if (service != null) {
|
||||
if (Adempiere.getThreadPoolExecutor() != null) {
|
||||
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int timeout = MSysConfig.getIntValue(MSysConfig.AUTOMATIC_PACKIN_INITIAL_DELAY, 120) * 1000;
|
||||
String folders = MSysConfig.getValue(MSysConfig.AUTOMATIC_PACKIN_FOLDERS);
|
||||
automaticPackin(timeout, folders, true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Adempiere.addServerStateChangeListener(new ServerStateChangeListener() {
|
||||
@Override
|
||||
public void stateChange(ServerStateChangeEvent event) {
|
||||
if (event.getEventType() == ServerStateChangeEvent.SERVER_START && service != null) {
|
||||
int timeout = MSysConfig.getIntValue(MSysConfig.AUTOMATIC_PACKIN_INITIAL_DELAY, 120) * 1000;
|
||||
String folders = MSysConfig.getValue(MSysConfig.AUTOMATIC_PACKIN_FOLDERS);
|
||||
automaticPackin(timeout, folders, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ import org.compiere.util.CLogger;
|
|||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Util;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkEvent;
|
||||
import org.osgi.framework.FrameworkListener;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
||||
|
@ -46,7 +48,7 @@ import org.osgi.util.tracker.ServiceTracker;
|
|||
* @author hengsin
|
||||
*
|
||||
*/
|
||||
public class Version2PackActivator extends AbstractActivator {
|
||||
public class Version2PackActivator extends AbstractActivator implements FrameworkListener {
|
||||
|
||||
protected final static CLogger logger = CLogger.getCLogger(Version2PackActivator.class.getName());
|
||||
|
||||
|
@ -54,6 +56,7 @@ public class Version2PackActivator extends AbstractActivator {
|
|||
public void start(BundleContext context) throws Exception {
|
||||
this.context = context;
|
||||
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
|
||||
context.addFrameworkListener(this);
|
||||
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
|
||||
serviceTracker.open();
|
||||
start();
|
||||
|
@ -233,6 +236,7 @@ public class Version2PackActivator extends AbstractActivator {
|
|||
public void stop(BundleContext context) throws Exception {
|
||||
stop();
|
||||
serviceTracker.close();
|
||||
context.removeFrameworkListener(this);
|
||||
this.context = null;
|
||||
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
|
||||
+ context.getBundle().getHeaders().get("Bundle-Version")
|
||||
|
@ -258,41 +262,6 @@ public class Version2PackActivator extends AbstractActivator {
|
|||
public IDictionaryService addingService(
|
||||
ServiceReference<IDictionaryService> reference) {
|
||||
service = context.getService(reference);
|
||||
if (Adempiere.getThreadPoolExecutor() != null) {
|
||||
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(Version2PackActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Adempiere.addServerStateChangeListener(new ServerStateChangeListener() {
|
||||
@Override
|
||||
public void stateChange(ServerStateChangeEvent event) {
|
||||
if (event.getEventType() == ServerStateChangeEvent.SERVER_START && service != null) {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(Version2PackActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -311,4 +280,51 @@ public class Version2PackActivator extends AbstractActivator {
|
|||
serverContext.setProperty("#AD_Client_ID", "0");
|
||||
ServerContext.setCurrentInstance(serverContext);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void frameworkEvent(FrameworkEvent event) {
|
||||
if (event.getType() == FrameworkEvent.STARTED) {
|
||||
frameworkStarted();
|
||||
}
|
||||
}
|
||||
|
||||
private void frameworkStarted() {
|
||||
if (service != null) {
|
||||
if (Adempiere.getThreadPoolExecutor() != null) {
|
||||
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(Version2PackActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Adempiere.addServerStateChangeListener(new ServerStateChangeListener() {
|
||||
@Override
|
||||
public void stateChange(ServerStateChangeEvent event) {
|
||||
if (event.getEventType() == ServerStateChangeEvent.SERVER_START && service != null) {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(Version2PackActivator.class.getClassLoader());
|
||||
setupPackInContext();
|
||||
installPackage();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
service = null;
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue