Search in sources :

Example 1 with Logger

use of com.codingchili.core.logging.Logger in project chili-core by codingchili.

the class ConfigurationsTest method testLoadDefaultsFromConfigurable.

@Test
public void testLoadDefaultsFromConfigurable(TestContext test) {
    Async async = test.async();
    Configurations.setWarnOnDefaultsLoaded(true);
    Configurations.initialize(new ContextMock(context) {

        @Override
        public Logger logger(Class aClass) {
            return new ConsoleLogger(aClass) {

                @Override
                public void onConfigurationDefaultsLoaded(String path, Class<?> clazz) {
                    if (path.equals(CoreStrings.testFile(CONFIGURATIONS, DEFAULT_JSON))) {
                        Configurations.reset();
                        async.complete();
                    }
                }
            };
        }
    });
    load(CoreStrings.testFile(CONFIGURATIONS, DEFAULT_JSON), ConfigurableTest.class);
}
Also used : Async(io.vertx.ext.unit.Async) ConsoleLogger(com.codingchili.core.logging.ConsoleLogger) ContextMock(com.codingchili.core.testing.ContextMock) Logger(com.codingchili.core.logging.Logger) ConsoleLogger(com.codingchili.core.logging.ConsoleLogger) ConfigurableTest(com.codingchili.core.configuration.ConfigurableTest)

Example 2 with Logger

use of com.codingchili.core.logging.Logger in project chili-core by codingchili.

the class Service method start.

@Override
public void start(Future<Void> start) {
    List<Future> deployments = new ArrayList<>();
    for (ListenerSettings listener : context.transports()) {
        handler = new RouterHandler(context);
        Future<String> future = Future.future();
        deployments.add(future);
        switch(listener.getType()) {
            case UDP:
                start(UdpListener::new, listener.getType(), future);
                break;
            case TCP:
                start(TcpListener::new, listener.getType(), future);
                break;
            case WEBSOCKET:
                start(WebsocketListener::new, listener.getType(), future);
                break;
            case REST:
                start(RestListener::new, listener.getType(), future);
                break;
        }
    }
    Logger logger = context.logger(getClass());
    all(deployments).setHandler(done -> {
        // logger.onServiceStarted(this);
        start.complete();
    });
}
Also used : RestListener(com.codingchili.core.listener.transport.RestListener) UdpListener(com.codingchili.core.listener.transport.UdpListener) RouterHandler(com.codingchili.router.controller.RouterHandler) ArrayList(java.util.ArrayList) WebsocketListener(com.codingchili.core.listener.transport.WebsocketListener) Future(io.vertx.core.Future) TcpListener(com.codingchili.core.listener.transport.TcpListener) Logger(com.codingchili.core.logging.Logger) ListenerSettings(com.codingchili.core.listener.ListenerSettings)

Example 3 with Logger

use of com.codingchili.core.logging.Logger in project chili-core by codingchili.

the class ListenerExceptionLogger method create.

/**
 * @param core     the core context.
 * @param listener the listener that the logger is created for.
 * @param handler  the handler that is attached to the listener.
 * @return a logger with metadata which includes information about the handler/listener.
 */
public static Logger create(CoreContext core, CoreListener listener, CoreHandler handler) {
    Logger logger = new RemoteLogger(core, handler.getClass());
    logger.setMetadataValue(LOG_LISTENER, listener.getClass()::getSimpleName);
    return logger;
}
Also used : RemoteLogger(com.codingchili.core.logging.RemoteLogger) Logger(com.codingchili.core.logging.Logger) RemoteLogger(com.codingchili.core.logging.RemoteLogger)

Example 4 with Logger

use of com.codingchili.core.logging.Logger in project chili-core by codingchili.

the class SystemContextTest method setUp.

@Before
public void setUp() {
    this.settings = Configurations.system();
    settings.getMetrics().setRate(100);
    settings.getMetrics().setEnabled(true);
    this.context = new ContextMock() {

        @Override
        public Logger logger(Class aClass) {
            return new AbstractLogger(getClass()) {

                @Override
                public void onMetricsSnapshot(JsonObject metrics) {
                    listener.onMetric(metrics);
                }
            };
        }

        @Override
        public SystemSettings system() {
            return settings;
        }
    };
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ContextMock(com.codingchili.core.testing.ContextMock) AbstractLogger(com.codingchili.core.logging.AbstractLogger) Logger(com.codingchili.core.logging.Logger) SystemSettings(com.codingchili.core.configuration.system.SystemSettings) AbstractLogger(com.codingchili.core.logging.AbstractLogger)

Example 5 with Logger

use of com.codingchili.core.logging.Logger in project chili-core by codingchili.

the class WebsocketListener method listen.

private void listen(Promise<Void> start) {
    Router router = Router.router(core.vertx());
    router.route().handler(BodyHandler.create().setBodyLimit(settings.getMaxRequestBytes()).setHandleFileUploads(false));
    RestHelper.addHeaders(router, settings.isSecure());
    router.routeWithRegex(".*").handler(request -> {
        // handle all attempts at performing a HTTP request.
        request.response().setStatusCode(HttpResponseStatus.ACCEPTED.code()).end(new JsonObject().put(PROTOCOL_STATUS, ResponseStatus.ACCEPTED).put(ID_MESSAGE, CoreStrings.getRestNotSupportedByWebsocketListener()).encodePrettily());
    });
    var handlerPromise = Promise.<Void>promise();
    handlerPromise.future().onSuccess((v) -> {
        core.vertx().createHttpServer(settings.getHttpOptions()).exceptionHandler(logger::onError).webSocketHandler(socket -> {
            Connection connection = connected(socket);
            socket.handler(data -> handle(connection, data));
            socket.closeHandler(closed -> connection.runCloseHandlers());
            socket.exceptionHandler(logger::onError);
        }).requestHandler(router).listen(settings.getPort(), getBindAddress(), listen -> {
            if (listen.succeeded()) {
                settings.addListenPort(listen.result().actualPort());
            } else {
                start.fail(listen.cause());
            }
        });
    }).onFailure(start::fail);
    handler.start(handlerPromise);
}
Also used : ServerWebSocket(io.vertx.core.http.ServerWebSocket) Promise(io.vertx.core.Promise) Router(io.vertx.ext.web.Router) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) CoreStrings(com.codingchili.core.configuration.CoreStrings) BodyHandler(io.vertx.ext.web.handler.BodyHandler) Logger(com.codingchili.core.logging.Logger) ResponseStatus(com.codingchili.core.protocol.ResponseStatus) Response(com.codingchili.core.protocol.Response) Buffer(io.vertx.core.buffer.Buffer) RequestPayloadSizeException(com.codingchili.core.protocol.exception.RequestPayloadSizeException) JsonObject(io.vertx.core.json.JsonObject) com.codingchili.core.listener(com.codingchili.core.listener) CoreContext(com.codingchili.core.context.CoreContext) RestHelper(com.codingchili.core.configuration.RestHelper) Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

Logger (com.codingchili.core.logging.Logger)5 ContextMock (com.codingchili.core.testing.ContextMock)2 JsonObject (io.vertx.core.json.JsonObject)2 ConfigurableTest (com.codingchili.core.configuration.ConfigurableTest)1 CoreStrings (com.codingchili.core.configuration.CoreStrings)1 RestHelper (com.codingchili.core.configuration.RestHelper)1 SystemSettings (com.codingchili.core.configuration.system.SystemSettings)1 CoreContext (com.codingchili.core.context.CoreContext)1 com.codingchili.core.listener (com.codingchili.core.listener)1 ListenerSettings (com.codingchili.core.listener.ListenerSettings)1 RestListener (com.codingchili.core.listener.transport.RestListener)1 TcpListener (com.codingchili.core.listener.transport.TcpListener)1 UdpListener (com.codingchili.core.listener.transport.UdpListener)1 WebsocketListener (com.codingchili.core.listener.transport.WebsocketListener)1 AbstractLogger (com.codingchili.core.logging.AbstractLogger)1 ConsoleLogger (com.codingchili.core.logging.ConsoleLogger)1 RemoteLogger (com.codingchili.core.logging.RemoteLogger)1 Response (com.codingchili.core.protocol.Response)1 ResponseStatus (com.codingchili.core.protocol.ResponseStatus)1 RequestPayloadSizeException (com.codingchili.core.protocol.exception.RequestPayloadSizeException)1