All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.webscoket.core.MessageHandlerFactory Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package io.github.webscoket.core;

import io.github.webscoket.core.handler.AbstractMessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.websocket.Session;
import java.util.List;

/**
 *    Genius
 *   2023/09/06 19:34
 **/
@Component
public class MessageHandlerFactory implements CommandLineRunner {

    private static List link;

    @Autowired
    public MessageHandlerFactory(List link){
        MessageHandlerFactory.link = link;
    }

    public static void doHandler(String msg, Session session){
        for (AbstractMessageHandler abstractMessageHandler : link) {
            if (abstractMessageHandler.check(msg)) {
                abstractMessageHandler.handler(msg,session);
                return;
            }
        }
    }

    public static AbstractMessageHandler getHandler(String type){
        for (AbstractMessageHandler abstractMessageHandler : link) {
            if (abstractMessageHandler.check(type)) {
                return abstractMessageHandler;
            }
        }
        return null;
    }

    @Override
    public void run(String... args) throws Exception {

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy