
com.hazelcast.jet.sql.impl.schema.TablesStorage Maven / Gradle / Ivy
/*
* Copyright 2021 Hazelcast Inc.
*
* Licensed under the Hazelcast Community License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://hazelcast.com/hazelcast-community-license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.jet.sql.impl.schema;
import com.hazelcast.cluster.Address;
import com.hazelcast.cluster.Member;
import com.hazelcast.cluster.memberselector.MemberSelectors;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.EntryListener;
import com.hazelcast.internal.serialization.Data;
import com.hazelcast.logging.ILogger;
import com.hazelcast.map.MapEvent;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import com.hazelcast.replicatedmap.ReplicatedMap;
import com.hazelcast.replicatedmap.impl.ReplicatedMapService;
import com.hazelcast.replicatedmap.impl.operation.GetOperation;
import com.hazelcast.spi.impl.NodeEngine;
import com.hazelcast.spi.impl.operationservice.Operation;
import com.hazelcast.spi.impl.operationservice.OperationService;
import com.hazelcast.sql.impl.schema.Mapping;
import com.hazelcast.sql.impl.schema.view.View;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
public class TablesStorage {
private static final int MAX_CHECK_ATTEMPTS = 5;
private static final long SLEEP_MILLIS = 100;
private static final String CATALOG_MAP_NAME = "__sql.catalog";
private final NodeEngine nodeEngine;
private final ILogger logger;
public TablesStorage(NodeEngine nodeEngine) {
this.nodeEngine = nodeEngine;
this.logger = nodeEngine.getLogger(getClass());
}
void put(String name, Mapping mapping) {
storage().put(name, mapping);
awaitMappingOnAllMembers(name, mapping);
}
void put(String name, View view) {
storage().put(name, view);
awaitMappingOnAllMembers(name, view);
}
boolean putIfAbsent(String name, Mapping mapping) {
Object previous = storage().putIfAbsent(name, mapping);
awaitMappingOnAllMembers(name, mapping);
return previous == null;
}
boolean putIfAbsent(String name, View view) {
Object previous = storage().putIfAbsent(name, view);
awaitMappingOnAllMembers(name, view);
return previous == null;
}
Mapping removeMapping(String name) {
return (Mapping) storage().remove(name);
}
View getView(String name) {
Object obj = storage().get(name);
if (obj instanceof View) {
return (View) obj;
}
return null;
}
View removeView(String name) {
return (View) storage().remove(name);
}
Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy