Skip to content

Commit

Permalink
Merge Space Templates - Meeds-io/MIPs#150 (#4131)
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker authored Nov 4, 2024
2 parents 9ea6e37 + 76a1b1c commit 4c5a329
Show file tree
Hide file tree
Showing 2,569 changed files with 17,254 additions and 22,292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ String getTranslationLabel(String objectType,
String fieldName,
Locale locale);

/**
* Retrieves the Translation Label for a given field of an Object (identified
* by its type and id) with a designated {@link Locale}. not.
*
* @param objectType Object type for which the Translation Metadata will be
* attached
* @param objectId Object unique identifier
* @param fieldName Object field
* @param locale {@link Locale}
* @return the translated label for a given {@link Locale}
*/
String getTranslationLabelOrDefault(String objectType,
long objectId,
String fieldName,
Locale locale);

/**
* Saves Translation Labels for a given Object's field. This will replace any
* existing list of translations
Expand Down Expand Up @@ -201,4 +217,5 @@ void deleteTranslationLabel(String objectType,
* @param objectType Object type
*/
void removePlugin(String objectType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,30 @@ public void removeListener(T listener) {
*/
protected void broadcast(final E event) {
for (final T listener : listeners) {
if (completionService.isAsync() || listener.getClass().isAnnotationPresent(Asynchronous.class)) {
completionService.addTask(new Callable<E>() {
public E call() throws Exception {
begin();
try {
dispatchEvent(listener, event);
} catch (Exception e) {
LOG.warn("Error dispatching event", e);
} finally {
end();
try {
if (completionService.isAsync() || listener.getClass().isAnnotationPresent(Asynchronous.class)) {
completionService.addTask(new Callable<E>() {
public E call() throws Exception {
begin();
try {
dispatchEvent(listener, event);
} catch (Exception e) {
LOG.warn("Error dispatching event", e);
} finally {
end();
}
return event;
}
return event;
}
});
} else {
try {
});
} else {
dispatchEvent(listener, event);
} catch (Exception e) {
LOG.warn("Error dispatching event", e);
}
} catch (Exception e) {
LOG.warn("Error dispatching event, source: {}, payload: {}. Continue braocasting other events.",
event.getSource(),
event.getPayload(),
e);
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.exoplatform.social.common.lifecycle;

import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -30,72 +29,56 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;

import lombok.SneakyThrows;

/**
* Process the callable request out of the http request.
*
* @author <a href="mailto:[email protected]">Alain Defrance</a>
* @version $Revision$
*/
@SuppressWarnings("rawtypes")
public class LifeCycleCompletionService implements Startable {

private final String THREAD_NUMBER_KEY = "thread-number";
private static final String THREAD_NUMBER_KEY = "thread-number";

private final String ASYNC_EXECUTION_KEY = "async-execution";
private static final String ASYNC_EXECUTION_KEY = "async-execution";

private Executor executor;
private static final int DEFAULT_THREAD_NUMBER = 1;

private ExecutorCompletionService ecs;
private static final boolean DEFAULT_ASYNC_EXECUTION = true;

private final int DEFAULT_THREAD_NUMBER = 1;
private ExecutorService executor;

private final boolean DEFAULT_ASYNC_EXECUTION = true;
private ExecutorCompletionService ecs;

private int configThreadNumber;
private int configThreadNumber;

private boolean configAsyncExecution;
private boolean configAsyncExecution;

public LifeCycleCompletionService(InitParams params) {
ValueParam threadNumber = params == null ? null : params.getValueParam(THREAD_NUMBER_KEY);
ValueParam asyncExecution = params == null ? null : params.getValueParam(ASYNC_EXECUTION_KEY);

//
ValueParam threadNumber = params.getValueParam(THREAD_NUMBER_KEY);
ValueParam asyncExecution = params.getValueParam(ASYNC_EXECUTION_KEY);

//
try {
this.configThreadNumber = Integer.valueOf(threadNumber.getValue());
}
catch (Exception e) {
this.configThreadNumber = DEFAULT_THREAD_NUMBER;
}

//
try {
this.configAsyncExecution = Boolean.valueOf(asyncExecution.getValue());
}
catch (Exception e) {
this.configAsyncExecution = DEFAULT_ASYNC_EXECUTION;
}

this.configThreadNumber = threadNumber == null ? DEFAULT_THREAD_NUMBER : Integer.valueOf(threadNumber.getValue());
this.configAsyncExecution = asyncExecution == null ? DEFAULT_ASYNC_EXECUTION : Boolean.valueOf(asyncExecution.getValue());
this.executor = Executors.newFixedThreadPool(this.configThreadNumber);

this.ecs = new ExecutorCompletionService(executor);
}

@Override
public void stop() {
executor.shutdown();
}

@SuppressWarnings("unchecked")
public void addTask(Callable callable) {
ecs.submit(callable);

}

@SneakyThrows
public void waitCompletionFinished() {
try {
if (executor instanceof ExecutorService) {
((ExecutorService) executor).awaitTermination(1, TimeUnit.SECONDS);
}
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
executor.awaitTermination(1, TimeUnit.SECONDS);
}

public boolean isAsync() {
Expand All @@ -105,27 +88,17 @@ public boolean isAsync() {
public long getActiveTaskCount() {
if (executor instanceof ThreadPoolExecutor threadPoolExecutor) {
return threadPoolExecutor.getActiveCount();
} else {
return 0;
}
return 0;
}

@SneakyThrows
public void waitAllTaskFinished(long timeout) {
long start = System.currentTimeMillis();
try {
while (getActiveTaskCount() != 0 && System.currentTimeMillis() - start <= timeout) {
Thread.sleep(100);
}
}
catch (InterruptedException e) {
throw new RuntimeException(e);
while (getActiveTaskCount() != 0 && System.currentTimeMillis() - start <= timeout) {
Thread.sleep(100);
}
}

public void start() {}

public void stop() {
if (executor instanceof ExecutorService) {
((ExecutorService) executor).shutdown();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public enum ActivityPluginType {
DEFAULT(""),
LINK("LINK_ACTIVITY"),
DOC("DOC_ACTIVITY"),
SPACE("SPACE_ACTIVITY"),
PROFILE("USER_PROFILE_ACTIVITY"),
FILE("files:spaces"),
SHARE_FILE("sharefiles:spaces"),
Expand Down

This file was deleted.

Loading

0 comments on commit 4c5a329

Please sign in to comment.