Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions core-common/src/main/java/org/apache/kylin/common/Closeable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.kylin.common;

public interface Closeable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my view, I suggest use java.io.Closeable instead. This interface looks needless.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is no IO operation and do not need throw IOException.

void close();
}
15 changes: 15 additions & 0 deletions core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,22 @@ public void clearManagers() {
return;
}

Map<Class, Closeable> closableManagers = new ConcurrentHashMap<>();

managersCache.forEach((key, value) -> {
if (value instanceof Closeable) {
closableManagers.put(key, (Closeable) value);
}
});

managersCache.clear();

if (closableManagers.size() > 0) {
closableManagers.forEach((key, value) -> {
logger.info("Close manager {}", key.getSimpleName());
value.close();
});
}
}

public Properties exportToProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.lang.StringUtils;
import org.apache.kylin.common.Closeable;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.restclient.RestClient;
import org.apache.kylin.common.util.ClassUtil;
Expand All @@ -57,7 +58,7 @@
* - on all servers, model listener is invoked, reload the model, and notify a "project_schema" update event
* - all listeners respond to the "project_schema" update -- reload cube desc, clear project L2 cache, clear calcite data source etc
*/
public class Broadcaster {
public class Broadcaster implements Closeable {

private static final Logger logger = LoggerFactory.getLogger(Broadcaster.class);

Expand Down Expand Up @@ -153,6 +154,11 @@ public void run() {
});
}

@Override
public void close() {
stopAnnounce();
}

private SyncErrorHandler getSyncErrorHandler(KylinConfig config) {
String clzName = config.getCacheSyncErrorHandler();
if (StringUtils.isEmpty(clzName)) {
Expand All @@ -166,8 +172,8 @@ public KylinConfig getConfig() {
}

public void stopAnnounce() {
announceThreadPool.shutdown();
announceMainLoop.shutdown();
announceThreadPool.shutdownNow();
announceMainLoop.shutdownNow();
}

// static listener survives cache wipe and goes after normal listeners
Expand Down