Search in sources :

Example 1 with MenuManagerServer

use of com.thecoderscorner.menu.mgr.MenuManagerServer in project tcMenu by davetcc.

the class MenuServerSocketIntegrationTest method setUp.

@BeforeEach
void setUp() throws IOException {
    var executor = Executors.newScheduledThreadPool(4);
    var tree = DomainFixtures.fullEspAmplifierTestTree();
    var authenticator = new PreDefinedAuthenticator("4321", List.of(new AuthenticationToken("integration-client", localUuid.toString())));
    serverConnection = new SocketServerConnectionManager(protocol, executor, 9876, Clock.systemDefaultZone());
    menuServer = new MenuManagerServer(executor, tree, "integration-test", serverUuid, authenticator, Clock.systemDefaultZone());
    menuServer.addConnectionManager(serverConnection);
    clientConnector = new SocketBasedConnector(new LocalIdentifier(localUuid, "integration-client"), executor, Clock.systemDefaultZone(), protocol, "localhost", 9876, ConnectMode.FULLY_AUTHENTICATED);
    clientController = new RemoteMenuController(clientConnector, new MenuTree());
    treePopulatedLatch = new CountDownLatch(1);
    correlationLatch = new CountDownLatch(1);
    itemUpdatedLatch = new CountDownLatch(1);
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) AuthenticationToken(com.thecoderscorner.menu.auth.PreDefinedAuthenticator.AuthenticationToken) MenuManagerServer(com.thecoderscorner.menu.mgr.MenuManagerServer) PreDefinedAuthenticator(com.thecoderscorner.menu.auth.PreDefinedAuthenticator) CountDownLatch(java.util.concurrent.CountDownLatch) SocketServerConnectionManager(com.thecoderscorner.menu.remote.mgrclient.SocketServerConnectionManager) SocketBasedConnector(com.thecoderscorner.menu.remote.socket.SocketBasedConnector) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MenuManagerServer

use of com.thecoderscorner.menu.mgr.MenuManagerServer in project tcMenu by davetcc.

the class SimpleWebSocketExample method main.

public static void main(String[] args) throws Exception {
    ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter(new SimpleFormatter());
    handler.setLevel(Level.FINEST);
    Logger.getLogger("").addHandler(handler);
    Logger.getLogger("").setLevel(Level.FINEST);
    var tree = DomainFixtures.fullEspAmplifierTestTree();
    var executor = Executors.newSingleThreadScheduledExecutor();
    var clock = Clock.systemDefaultZone();
    MenuCommandProtocol tagValProtocol = new TagValMenuCommandProtocol();
    var menuManager = new MenuManagerServer(executor, tree, "WS Test", UUID.randomUUID(), new PropertiesAuthenticator("./auth.properties", new NoDialogFacilities()), clock);
    menuManager.addConnectionManager(new WebSocketServerConnectionManager(tagValProtocol, 3333, clock));
    menuManager.addConnectionManager(new SocketServerConnectionManager(tagValProtocol, executor, 3334, clock));
    menuManager.start();
    var menuList = menuManager.getManagedMenu().getMenuById(21).orElseThrow();
    menuManager.updateMenuItem(menuList, List.of("salad", "pasta", "pizza"));
    if (Boolean.getBoolean("sendSimulatedUpdates")) {
        executor.scheduleAtFixedRate(() -> {
            menuManager.updateMenuItem(menuList, randomListData());
        }, 5000, 5000, TimeUnit.MILLISECONDS);
        executor.scheduleAtFixedRate(() -> {
            if (menuManager.isAnyRemoteConnection())
                return;
            var menuVolume = (AnalogMenuItem) tree.getMenuById(1).orElseThrow();
            var menuLeftVU = (AnalogMenuItem) tree.getMenuById(15).orElseThrow();
            var menuRightVU = (AnalogMenuItem) tree.getMenuById(16).orElseThrow();
            int amt = (int) (Math.random() * 2000);
            if (Math.random() > 0.5) {
                menuManager.updateMenuItem(menuLeftVU, MenuItemHelper.getValueFor(menuLeftVU, tree, 0) + amt);
                menuManager.updateMenuItem(menuRightVU, MenuItemHelper.getValueFor(menuRightVU, tree, 0) - amt);
            } else {
                menuManager.updateMenuItem(menuLeftVU, MenuItemHelper.getValueFor(menuLeftVU, tree, 0) - amt);
                menuManager.updateMenuItem(menuRightVU, MenuItemHelper.getValueFor(menuRightVU, tree, 0) + amt);
            }
            menuManager.updateMenuItem(menuVolume, Math.random() * menuVolume.getMaxValue());
        }, 150, 150, TimeUnit.MILLISECONDS);
    }
}
Also used : TagValMenuCommandProtocol(com.thecoderscorner.menu.remote.protocol.TagValMenuCommandProtocol) AnalogMenuItem(com.thecoderscorner.menu.domain.AnalogMenuItem) MenuCommandProtocol(com.thecoderscorner.menu.remote.MenuCommandProtocol) TagValMenuCommandProtocol(com.thecoderscorner.menu.remote.protocol.TagValMenuCommandProtocol) MenuManagerServer(com.thecoderscorner.menu.mgr.MenuManagerServer) SimpleFormatter(java.util.logging.SimpleFormatter) PropertiesAuthenticator(com.thecoderscorner.menu.auth.PropertiesAuthenticator) NoDialogFacilities(com.thecoderscorner.menu.mgr.NoDialogFacilities) ConsoleHandler(java.util.logging.ConsoleHandler) SocketServerConnectionManager(com.thecoderscorner.menu.remote.mgrclient.SocketServerConnectionManager)

Aggregations

MenuManagerServer (com.thecoderscorner.menu.mgr.MenuManagerServer)2 SocketServerConnectionManager (com.thecoderscorner.menu.remote.mgrclient.SocketServerConnectionManager)2 PreDefinedAuthenticator (com.thecoderscorner.menu.auth.PreDefinedAuthenticator)1 AuthenticationToken (com.thecoderscorner.menu.auth.PreDefinedAuthenticator.AuthenticationToken)1 PropertiesAuthenticator (com.thecoderscorner.menu.auth.PropertiesAuthenticator)1 AnalogMenuItem (com.thecoderscorner.menu.domain.AnalogMenuItem)1 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)1 NoDialogFacilities (com.thecoderscorner.menu.mgr.NoDialogFacilities)1 MenuCommandProtocol (com.thecoderscorner.menu.remote.MenuCommandProtocol)1 TagValMenuCommandProtocol (com.thecoderscorner.menu.remote.protocol.TagValMenuCommandProtocol)1 SocketBasedConnector (com.thecoderscorner.menu.remote.socket.SocketBasedConnector)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ConsoleHandler (java.util.logging.ConsoleHandler)1 SimpleFormatter (java.util.logging.SimpleFormatter)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1