forked from Linyuzai/concept
-
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.
- Loading branch information
tanghanzheng
committed
Jul 22, 2022
1 parent
8d7e36c
commit 1c60512
Showing
16 changed files
with
345 additions
and
17 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
71 changes: 70 additions & 1 deletion
71
sample/src/main/java/com/github/linyuzai/concept/sample/ConceptSampleApplication.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 |
---|---|---|
@@ -1,14 +1,83 @@ | ||
package com.github.linyuzai.concept.sample; | ||
|
||
import com.github.linyuzai.concept.sample.sync.MapBlockingQueue; | ||
import lombok.SneakyThrows; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import java.io.Serializable; | ||
import java.lang.reflect.*; | ||
import java.util.*; | ||
//import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
//@EnableSwagger2 | ||
@SpringBootApplication | ||
@SpringBootApplication(scanBasePackages = "com.github.linyuzai.concept.sample.event") | ||
public class ConceptSampleApplication { | ||
|
||
private final MapBlockingQueue<String> queue = new MapBlockingQueue<>(); | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ConceptSampleApplication.class, args); | ||
} | ||
|
||
@SneakyThrows | ||
public static void test() { | ||
long sleep = 100; | ||
ConceptSampleApplication application = new ConceptSampleApplication(); | ||
application.startPut("A"); | ||
Thread.sleep(sleep); | ||
application.startPut("B"); | ||
Thread.sleep(sleep); | ||
application.startPut("C"); | ||
Thread.sleep(sleep); | ||
application.startPut("D"); | ||
Thread.sleep(sleep); | ||
application.startTake(); | ||
} | ||
|
||
@SneakyThrows | ||
public void startTake() { | ||
while (true) { | ||
String s = queue.take(); | ||
System.out.println(s); | ||
System.out.println(queue.size() + ":" + queue.getMap()); | ||
Thread.sleep(1000); | ||
} | ||
} | ||
|
||
public void startPut(String s) { | ||
new Thread() { | ||
|
||
int i; | ||
|
||
@SneakyThrows | ||
@Override | ||
public void run() { | ||
while (true) { | ||
queue.put(s, s + i++); | ||
Thread.sleep(100); | ||
} | ||
} | ||
}.start(); | ||
|
||
} | ||
|
||
public class StringArrayList extends ArrayList<String> { | ||
|
||
} | ||
|
||
public class ClassArrayList extends ArrayList<Class<? extends Serializable>> { | ||
|
||
} | ||
|
||
public class ClassesArrayList extends ArrayList<Class<? extends Serializable>[]> { | ||
|
||
} | ||
|
||
public class Custom<T extends String & Serializable & Cloneable> { | ||
} | ||
|
||
public interface CustomEx extends Serializable, Cloneable { | ||
|
||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...zai/concept/sample/connection/loadbalance/websocket/socketio/SocketIOWebSocketServer.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,34 @@ | ||
package com.github.linyuzai.concept.sample.connection.loadbalance.websocket.socketio; | ||
|
||
import io.socket.engineio.server.Emitter; | ||
import io.socket.engineio.server.EngineIoServer; | ||
import io.socket.socketio.server.SocketIoServer; | ||
import org.springframework.web.socket.server.HandshakeInterceptor; | ||
|
||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
//@WebServlet("/websocket/*") | ||
public class SocketIOWebSocketServer extends HttpServlet { | ||
|
||
private final EngineIoServer mEngineIoServer = new EngineIoServer(); | ||
private final SocketIoServer mSocketIoServer = new SocketIoServer(mEngineIoServer); | ||
|
||
public SocketIOWebSocketServer() { | ||
mSocketIoServer.namespace("/websocket/").on("connection", new Emitter.Listener() { | ||
@Override | ||
public void call(Object... args) { | ||
|
||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
mEngineIoServer.handleRequest(request, response); | ||
//mSocketIoServer.namespace("/websocket/*").broadcast(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
sample/src/main/java/com/github/linyuzai/concept/sample/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,9 @@ | ||
package com.github.linyuzai.concept.sample.event; | ||
|
||
import com.github.linyuzai.event.autoconfigure.EnableEventConcept; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@EnableEventConcept | ||
@Configuration | ||
public class EventConfig { | ||
} |
23 changes: 23 additions & 0 deletions
23
sample/src/main/java/com/github/linyuzai/concept/sample/event/kafka/KafkaEventConfig.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 com.github.linyuzai.concept.sample.event.kafka; | ||
|
||
import com.github.linyuzai.event.core.codec.EventDecoder; | ||
import com.github.linyuzai.event.core.codec.EventEncoder; | ||
import com.github.linyuzai.event.core.codec.JacksonEventDecoder; | ||
import com.github.linyuzai.event.core.codec.JacksonEventEncoder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
//@EnableKafka | ||
@Configuration | ||
public class KafkaEventConfig { | ||
|
||
@Bean | ||
public EventEncoder eventEncoder() { | ||
return new JacksonEventEncoder(); | ||
} | ||
|
||
@Bean | ||
public EventDecoder eventDecoder() { | ||
return new JacksonEventDecoder(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...le/src/main/java/com/github/linyuzai/concept/sample/event/kafka/KafkaEventController.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 com.github.linyuzai.concept.sample.event.kafka; | ||
|
||
import com.github.linyuzai.event.core.concept.EventConcept; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/concept-event") | ||
public class KafkaEventController { | ||
|
||
@Autowired | ||
private EventConcept concept; | ||
|
||
@GetMapping("/kafka") | ||
public void send() { | ||
concept.event("123").publish(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ain/java/com/github/linyuzai/concept/sample/event/kafka/KafkaEventSubscriberRegister.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 com.github.linyuzai.concept.sample.event.kafka; | ||
|
||
import com.github.linyuzai.event.core.concept.EventConcept; | ||
import com.github.linyuzai.event.core.context.EventContext; | ||
import com.github.linyuzai.event.kafka.exchange.KafkaEngineExchange; | ||
import com.github.linyuzai.event.kafka.endpoint.KafkaEventEndpoint; | ||
import com.github.linyuzai.event.kafka.subscriber.TopicKafkaEventSubscriber; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.kafka.support.Acknowledgment; | ||
|
||
@Configuration | ||
public class KafkaEventSubscriberRegister implements ApplicationRunner { | ||
|
||
@Autowired | ||
public EventConcept concept; | ||
|
||
//@KafkaListener(topics = "sample", containerFactory = "localKafkaListenerContainerFactory") | ||
public void receiveLocal(String msg, Acknowledgment acknowledgment) { | ||
System.out.println("local-" + msg); | ||
acknowledgment.acknowledge(); | ||
} | ||
|
||
//@KafkaListener(topics = "sample", containerFactory = "devKafkaListenerContainerFactory") | ||
public void receiveDev(String msg, Acknowledgment acknowledgment) { | ||
System.out.println("dev-" + msg); | ||
acknowledgment.acknowledge(); | ||
} | ||
|
||
@Override | ||
public void run(ApplicationArguments args) throws Exception { | ||
concept.event(String.class) | ||
.exchange(new KafkaEngineExchange()) | ||
.subscribe(new TopicKafkaEventSubscriber<String>("sample") { | ||
@Override | ||
public void onEvent(String event, KafkaEventEndpoint endpoint, EventContext context) { | ||
System.out.println("subscribe-" + endpoint.getName() + ":" + event); | ||
} | ||
}); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
sample/src/main/java/com/github/linyuzai/concept/sample/plugin/Device.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,6 @@ | ||
package com.github.linyuzai.concept.sample.plugin; | ||
|
||
public interface Device { | ||
|
||
String getDeviceType(); | ||
} |
15 changes: 15 additions & 0 deletions
15
sample/src/main/java/com/github/linyuzai/concept/sample/plugin/DeviceOperation.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,15 @@ | ||
package com.github.linyuzai.concept.sample.plugin; | ||
|
||
public interface DeviceOperation { | ||
|
||
/** | ||
* 设备操作 | ||
* | ||
* @param device 设备 | ||
* @param opType 操作类型 | ||
* @param opValue 操作值 | ||
* @return 操作结果 | ||
*/ | ||
OperationResult operate(Device device, String opType, Object opValue); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...main/java/com/github/linyuzai/concept/sample/plugin/DeviceOperationNotFoundException.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,7 @@ | ||
package com.github.linyuzai.concept.sample.plugin; | ||
|
||
public class DeviceOperationNotFoundException extends RuntimeException { | ||
public DeviceOperationNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
sample/src/main/java/com/github/linyuzai/concept/sample/plugin/OperationResult.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,5 @@ | ||
package com.github.linyuzai.concept.sample.plugin; | ||
|
||
public class OperationResult { | ||
|
||
} |
Oops, something went wrong.