Skip to content

Commit

Permalink
for #1172, add ShardingEventHandlerLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 24, 2018
1 parent f0b7a94 commit 16d6481
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* Sharding event handler.
*
* @author zhangliang
* @param <S> type of sharding start event
* @param <F> type of sharding finish event
* @param <S> type of start event
* @param <F> type of finish event
*/
public interface ShardingEventHandler<S extends ShardingStartEvent, F extends ShardingFinishEvent> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* 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.
* </p>
*/

package io.shardingsphere.core.spi.event;

/**
* Sharding event handler loader.
*
* @author zhangliang
* @param <S> type of start event
* @param <F> type of finish event
*/
public interface ShardingEventHandlerLoader<S extends ShardingStartEvent, F extends ShardingFinishEvent> {

/**
* Handle start event.
*
* @param event start event
*/
void start(S event);

/**
* Handle finish event.
*
* @param event finish event
*/
void finish(F event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

package io.shardingsphere.core.spi.event.connection.close;

import io.shardingsphere.core.spi.event.ShardingEventHandlerLoader;

import java.util.ServiceLoader;

/**
* Connection event handler loader.
*
* @author zhangliang
*/
public final class CloseConnectionEventHandlerLoader {
public final class CloseConnectionEventHandlerLoader implements ShardingEventHandlerLoader<CloseConnectionStartEvent, CloseConnectionFinishEvent> {

private static final CloseConnectionEventHandlerLoader INSTANCE = new CloseConnectionEventHandlerLoader();

Expand All @@ -43,22 +45,14 @@ public static CloseConnectionEventHandlerLoader getInstance() {
return INSTANCE;
}

/**
* Handle close connection start event.
*
* @param event get connection start event
*/
@Override
public void start(final CloseConnectionStartEvent event) {
for (CloseConnectionEventHandler each : serviceLoader) {
each.start(event);
}
}

/**
* Handle close connection finish event.
*
* @param event get connection finish event
*/
@Override
public void finish(final CloseConnectionFinishEvent event) {
for (CloseConnectionEventHandler each : serviceLoader) {
each.finish(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

package io.shardingsphere.core.spi.event.connection.get;

import io.shardingsphere.core.spi.event.ShardingEventHandlerLoader;

import java.util.ServiceLoader;

/**
* Connection event handler loader.
*
* @author zhangliang
*/
public final class GetConnectionEventHandlerLoader {
public final class GetConnectionEventHandlerLoader implements ShardingEventHandlerLoader<GetConnectionStartEvent, GetConnectionFinishEvent> {

private static final GetConnectionEventHandlerLoader INSTANCE = new GetConnectionEventHandlerLoader();

Expand All @@ -43,22 +45,14 @@ public static GetConnectionEventHandlerLoader getInstance() {
return INSTANCE;
}

/**
* Handle get connection start event.
*
* @param event get connection start event
*/
@Override
public void start(final GetConnectionStartEvent event) {
for (GetConnectionEventHandler each : serviceLoader) {
each.start(event);
}
}

/**
* Handle get connection finish event.
*
* @param event get connection finish event
*/
@Override
public void finish(final GetConnectionFinishEvent event) {
for (GetConnectionEventHandler each : serviceLoader) {
each.finish(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

package io.shardingsphere.core.spi.event.executor;

import io.shardingsphere.core.spi.event.ShardingEventHandlerLoader;

import java.util.ServiceLoader;

/**
* SQL Execution event handler loader.
*
* @author zhangliang
*/
public final class SQLExecutionEventHandlerLoader {
public final class SQLExecutionEventHandlerLoader implements ShardingEventHandlerLoader<SQLExecutionStartEvent, SQLExecutionFinishEvent> {

private static final SQLExecutionEventHandlerLoader INSTANCE = new SQLExecutionEventHandlerLoader();

Expand All @@ -43,22 +45,14 @@ public static SQLExecutionEventHandlerLoader getInstance() {
return INSTANCE;
}

/**
* Handle SQL execution start event.
*
* @param event SQL execution start event
*/
@Override
public void start(final SQLExecutionStartEvent event) {
for (SQLExecutionEventHandler each : serviceLoader) {
each.start(event);
}
}

/**
* Handle SQL execution finish event.
*
* @param event SQL execution finish event
*/
@Override
public void finish(final SQLExecutionFinishEvent event) {
for (SQLExecutionEventHandler each : serviceLoader) {
each.finish(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

package io.shardingsphere.core.spi.event.parsing;

import io.shardingsphere.core.spi.event.ShardingEventHandlerLoader;

import java.util.ServiceLoader;

/**
* Parsing event handler loader.
*
* @author zhangliang
*/
public final class ParsingEventHandlerLoader {
public final class ParsingEventHandlerLoader implements ShardingEventHandlerLoader<ParsingStartEvent, ParsingFinishEvent> {

private static final ParsingEventHandlerLoader INSTANCE = new ParsingEventHandlerLoader();

Expand All @@ -43,22 +45,14 @@ public static ParsingEventHandlerLoader getInstance() {
return INSTANCE;
}

/**
* Handle parsing start event.
*
* @param event parsing start event
*/
@Override
public void start(final ParsingStartEvent event) {
for (ParsingEventHandler each : serviceLoader) {
each.start(event);
}
}

/**
* Handle parsing finish event.
*
* @param event parsing finish event
*/
@Override
public void finish(final ParsingFinishEvent event) {
for (ParsingEventHandler each : serviceLoader) {
each.finish(event);
Expand Down

0 comments on commit 16d6481

Please sign in to comment.