justinwwhuang commented on code in PR #9162: URL: https://github.com/apache/inlong/pull/9162#discussion_r1376985650
########## inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/instance/FileInstance.java: ########## @@ -0,0 +1,159 @@ +/* + * 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.inlong.agent.plugin.instance; + +import org.apache.inlong.agent.conf.InstanceProfile; +import org.apache.inlong.agent.constant.TaskConstants; +import org.apache.inlong.agent.core.instance.ActionType; +import org.apache.inlong.agent.core.instance.InstanceAction; +import org.apache.inlong.agent.core.instance.InstanceManager; +import org.apache.inlong.agent.core.task.OffsetManager; +import org.apache.inlong.agent.plugin.Instance; +import org.apache.inlong.agent.plugin.Message; +import org.apache.inlong.agent.plugin.file.Sink; +import org.apache.inlong.agent.plugin.file.Source; +import org.apache.inlong.agent.plugin.utils.file.FileDataUtils; +import org.apache.inlong.agent.state.State; +import org.apache.inlong.agent.utils.AgentUtils; +import org.apache.inlong.agent.utils.ThreadUtils; +import org.apache.inlong.common.enums.InstanceStateEnum; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class FileInstance extends Instance { + + private static final Logger LOGGER = LoggerFactory.getLogger(FileInstance.class); + private Source source; + private Sink sink; + private InstanceProfile profile; + public static final int CORE_THREAD_SLEEP_TIME = 1; + private InstanceManager instanceManager; + private volatile boolean running = false; + private volatile boolean inited = false; + + @Override + public void init(Object srcManager, InstanceProfile srcProfile) { + try { + instanceManager = (InstanceManager) srcManager; + profile = srcProfile; + profile.set(TaskConstants.INODE_INFO, FileDataUtils.getInodeInfo(profile.getInstanceId())); + LOGGER.info("task id: {} submit new instance {} profile detail {}.", profile.getTaskId(), + profile.getInstanceId(), profile.toJsonStr()); + source = (Source) Class.forName(profile.getSourceClass()).newInstance(); + source.init(profile); + sink = (Sink) Class.forName(profile.getSinkClass()).newInstance(); + sink.init(profile); + inited = true; + } catch (Throwable ex) { + doChangeState(State.FATAL); + LOGGER.error("init instance {} for task {} failed", profile.getInstanceId(), profile.getInstanceId(), + ex); + ThreadUtils.threadThrowableHandler(Thread.currentThread(), ex); + } + } + + @Override + public void destroy() { + if (!inited) { + return; + } + doChangeState(State.SUCCEEDED); + while (running) { + AgentUtils.silenceSleepInMs(1); Review Comment: get, fix it next issue -- 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: commits-unsubscr...@inlong.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org