You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2019/08/08 02:15:20 UTC

[servicecomb-pack] 06/10: SCB-1417 delete fsm channel redis

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git

commit 703d4b3f6fef8f8f804916a523ca36ab212374c0
Author: CMonkey <42...@gmail.com>
AuthorDate: Wed Aug 7 10:45:15 2019 +0800

    SCB-1417 delete fsm channel redis
---
 .../alpha/fsm/channel/redis/MessagePublisher.java  | 23 ------
 .../alpha/fsm/channel/redis/MessageSerializer.java | 86 ----------------------
 .../fsm/channel/redis/RedisMessagePublisher.java   | 45 -----------
 .../fsm/channel/redis/RedisMessageSubscriber.java  | 70 ------------------
 4 files changed, 224 deletions(-)

diff --git a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/MessagePublisher.java b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/MessagePublisher.java
deleted file mode 100644
index 292877f..0000000
--- a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/MessagePublisher.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.servicecomb.pack.alpha.fsm.channel.redis;
-
-public interface MessagePublisher {
-
-    void publish(Object data);
-
-}
diff --git a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/MessageSerializer.java b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/MessageSerializer.java
deleted file mode 100644
index 711bb07..0000000
--- a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/MessageSerializer.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.servicecomb.pack.alpha.fsm.channel.redis;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.data.redis.serializer.RedisSerializer;
-import org.springframework.data.redis.serializer.SerializationException;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.Optional;
-
-public class MessageSerializer {
-
-    private static final Logger logger = LoggerFactory.getLogger(MessageSerializer.class);
-
-    private static MessageSerializerImpl serializer = null;
-
-    public MessageSerializer() {
-        serializer = new MessageSerializerImpl();
-    }
-
-    public Optional<byte[]> serializer(Object data){
-        return Optional.ofNullable(serializer.serialize(data));
-    }
-
-    public Optional<Object> deserialize(byte[] bytes){
-        return Optional.ofNullable(serializer.deserialize(bytes));
-    }
-
-    private class MessageSerializerImpl implements RedisSerializer<Object>{
-        @Override
-        public byte[] serialize(Object data) throws SerializationException {
-            try {
-                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-                ObjectOutputStream outputStream = new ObjectOutputStream(byteArrayOutputStream);
-                outputStream.writeObject(data);
-
-                byte[] bytes = byteArrayOutputStream.toByteArray();
-
-                outputStream.close();
-
-                return bytes;
-            }catch (Exception e){
-                logger.error("serialize Exception = [{}]", e.getMessage(), e);
-            }
-
-            return null;
-        }
-
-        @Override
-        public Object deserialize(byte[] bytes) throws SerializationException {
-            try {
-                ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
-                ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
-
-                Object object = objectInputStream.readObject();
-
-                objectInputStream.close();
-
-                return object;
-            }catch (Exception e){
-                logger.error("deserialize Exception = [{}]", e.getMessage(), e);
-            }
-
-            return null;
-        }
-    }
-}
diff --git a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/RedisMessagePublisher.java b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/RedisMessagePublisher.java
deleted file mode 100644
index f1e0363..0000000
--- a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/RedisMessagePublisher.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.servicecomb.pack.alpha.fsm.channel.redis;
-
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.listener.ChannelTopic;
-
-public class RedisMessagePublisher implements MessagePublisher {
-
-    private static final Logger logger = LoggerFactory.getLogger(RedisMessagePublisher.class);
-
-    private RedisTemplate<String, Object> redisTemplate;
-    private ChannelTopic channelTopic;
-
-    public RedisMessagePublisher(RedisTemplate<String, Object> redisTemplate, ChannelTopic channelTopic) {
-        this.redisTemplate = redisTemplate;
-        this.channelTopic = channelTopic;
-    }
-
-    @Override
-    public void publish(Object data) {
-        if(logger.isDebugEnabled()) {
-            logger.debug("send message [{}] to [{}]", data, channelTopic.getTopic());
-        }
-        redisTemplate.convertAndSend(channelTopic.getTopic(), data);
-
-    }
-}
diff --git a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/RedisMessageSubscriber.java b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/RedisMessageSubscriber.java
deleted file mode 100644
index 3f11134..0000000
--- a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/channel/redis/RedisMessageSubscriber.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.servicecomb.pack.alpha.fsm.channel.redis;
-
-import org.apache.servicecomb.pack.alpha.core.NodeStatus;
-import org.apache.servicecomb.pack.alpha.core.fsm.event.base.BaseEvent;
-import org.apache.servicecomb.pack.alpha.core.fsm.sink.ActorEventSink;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.data.redis.connection.Message;
-import org.springframework.data.redis.connection.MessageListener;
-
-import java.nio.charset.StandardCharsets;
-
-public class RedisMessageSubscriber implements MessageListener {
-
-    private static final Logger logger = LoggerFactory.getLogger(RedisMessageSubscriber.class);
-
-    private ActorEventSink actorEventSink;
-    private NodeStatus nodeStatus;
-
-    private MessageSerializer messageSerializer = new MessageSerializer();
-
-    public RedisMessageSubscriber(ActorEventSink actorEventSink, NodeStatus nodeStatus) {
-        this.actorEventSink = actorEventSink;
-        this.nodeStatus = nodeStatus;
-    }
-
-    @Override
-    public void onMessage(Message message, byte[] pattern) {
-        if(nodeStatus.isMaster()) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("pattern = [{}]", new String(pattern, StandardCharsets.UTF_8));
-            }
-
-            messageSerializer.deserialize(message.getBody()).ifPresent(data -> {
-
-                BaseEvent event = (BaseEvent) data;
-
-                if (logger.isDebugEnabled()) {
-                    logger.debug("event = [{}]", event);
-                }
-
-                try {
-                    actorEventSink.send(event);
-                } catch (Exception e) {
-                    logger.error("subscriber Exception = [{}]", e.getMessage(), e);
-                }
-            });
-        }else{
-            if(logger.isDebugEnabled()){
-                logger.debug("nodeStatus is not master and cancel this time subscribe");
-            }
-        }
-    }
-}