-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API - v0.1.6
- Loading branch information
Showing
15 changed files
with
171 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Core/src/main/java/allchive/server/core/async/CustomAsyncExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package allchive.server.core.async; | ||
|
||
|
||
import java.lang.reflect.Method; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class CustomAsyncExceptionHandler implements AsyncUncaughtExceptionHandler { | ||
|
||
@Override | ||
public void handleUncaughtException(Throwable throwable, Method method, Object... params) { | ||
log.error("Exception message - " + throwable); | ||
log.error("Method name - " + method.getName()); | ||
for (Object param : params) { | ||
log.error("Parameter value - " + param); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Core/src/main/java/allchive/server/core/config/EnableAsyncConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package allchive.server.core.config; | ||
|
||
import static allchive.server.core.consts.AllchiveConst.*; | ||
|
||
import allchive.server.core.async.CustomAsyncExceptionHandler; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
@EnableAsync | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class EnableAsyncConfig implements AsyncConfigurer { | ||
|
||
private final CustomAsyncExceptionHandler customAsyncExceptionHandler; | ||
|
||
@Override | ||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { | ||
return customAsyncExceptionHandler; | ||
} | ||
|
||
@Bean(name = "s3ImageTaskExecutor") | ||
public Executor s3ImageTaskExecutor() { | ||
return createTaskExecutor("S3_IMAGE_TASK_EXECUTOR"); | ||
} | ||
|
||
private Executor createTaskExecutor(String name) { | ||
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); | ||
taskExecutor.setCorePoolSize(CORE_POOL_SIZE); | ||
taskExecutor.setMaxPoolSize(MAX_POOL_SIZE); | ||
taskExecutor.setQueueCapacity(QUEUE_CAPACITY); | ||
taskExecutor.setThreadNamePrefix(name); | ||
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); | ||
taskExecutor.initialize(); | ||
return taskExecutor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package allchive.server.core.event; | ||
|
||
|
||
import org.springframework.context.ApplicationEventPublisher; | ||
|
||
public class Event { | ||
private static ApplicationEventPublisher publisher; | ||
|
||
static void setPublisher(ApplicationEventPublisher publisher) { | ||
Event.publisher = publisher; | ||
} | ||
|
||
public static void raise(Object event) { | ||
if (publisher != null) { | ||
publisher.publishEvent(event); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Core/src/main/java/allchive/server/core/event/EventConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package allchive.server.core.event; | ||
|
||
|
||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class EventConfig { | ||
@Autowired private ApplicationEventPublisher applicationEventPublisher; | ||
|
||
@Bean | ||
public InitializingBean eventsInitializer() { | ||
return () -> Event.setPublisher(applicationEventPublisher); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Core/src/main/java/allchive/server/core/event/events/s3/S3ImageDeleteEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package allchive.server.core.event.events.s3; | ||
|
||
|
||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class S3ImageDeleteEvent { | ||
private final List<String> keys; | ||
|
||
@Builder | ||
private S3ImageDeleteEvent(List<String> keys) { | ||
this.keys = keys; | ||
} | ||
|
||
public static S3ImageDeleteEvent from(List<String> keys) { | ||
return S3ImageDeleteEvent.builder().keys(keys).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters