nevdmitry commented on code in PR #3430: URL: https://github.com/apache/ignite-3/pull/3430#discussion_r1532262289
########## modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/event/exception/InvalidEventTypeException.java: ########## @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.ignite.internal.eventlog.event.exception; + +import static org.apache.ignite.lang.ErrorGroups.Common.ILLEGAL_ARGUMENT_ERR; + +import org.apache.ignite.internal.lang.IgniteInternalException; + +/** Thrown when an event type is not registered in EventTypeRegistry. */ +public class InvalidEventTypeException extends IgniteInternalException { + private static final long serialVersionUID = 3974826166860537715L; + + private static final String MSG_FORMAT = "Invalid event type `%s` during event creation. " Review Comment: there is no verb in `Invalid event type `%s` during event creation.` ########## modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/event/EventTypeRegistry.java: ########## @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.ignite.internal.eventlog.event; + +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.ignite.internal.eventlog.event.exception.NotUniqueEventTypeException; + +/** + * Registry of all event types that are known to the system. Every new event type must be registered in this registry once. + * For the example of usage, see {@link IgniteEvents}. The class is thread-safe. + */ +public final class EventTypeRegistry { + private static final Object DUMMY = new Object(); + + private static final ConcurrentHashMap<String, Object> allTypes = new ConcurrentHashMap<>(); + + /** Registers a set of event types. */ + public static void register(Set<String> types) { Review Comment: theoretically concurrentmodification exeption can be thrown here if `types` will be not thread safe ########## modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/event/IgniteEvents.java: ########## @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.ignite.internal.eventlog.event; + +import java.util.Arrays; +import org.apache.ignite.internal.eventlog.api.Event; +import org.apache.ignite.internal.eventlog.api.EventFactory; + +/** + * The main class for creating all Ignite events. + * + * <p>If you want to create an instance of the Event with the specified type, use the {@link #create} method. + * + * <p>For example, to create an event of the type CONNECTION_ESTABLISHED: + * <pre>{@code IgniteEvents.CONNECTION_ESTABLISHED.create(EventUser.system());}</pre> + */ +public final class IgniteEvents implements EventFactory { + public static final IgniteEvents CONNECTION_ESTABLISHED = new IgniteEvents(IgniteEventTypes.CONNECTION_ESTABLISHED.name()); + + public static final IgniteEvents CONNECTION_CLOSED = new IgniteEvents(IgniteEventTypes.CONNECTION_CLOSED.name()); + + static { + Arrays.stream(IgniteEventTypes.values()).forEach(type -> EventTypeRegistry.register(type.name())); + } + + private final String type; + + private IgniteEvents(String type) { + this.type = type; + } + + @Override + public Event create(EventUser user) { + return Event.builder() + .type(type) + .user(user) + .timestamp(System.currentTimeMillis()) + .productVersion("3.0.0") Review Comment: hard coded product version looks weird, can we do something with it? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
