You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/07/16 09:22:00 UTC

[GitHub] [shardingsphere-elasticjob] Technoboy- commented on issue #1085: Shard is not working when instance node removes

Technoboy- commented on issue #1085:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1085#issuecomment-659288940


   The reason is described below:
   ```
   public abstract class AbstractJobListener implements CuratorCacheListener {
       
       @Override
       public final void event(final Type type, final ChildData oldData, final ChildData data) {
           if (null == data) {
               return;
           }
           String path = data.getPath();
           if (path.isEmpty()) {
               return;
           }
           dataChanged(path, type, null == data.getData() ? "" : new String(data.getData(), Charsets.UTF_8));
       }
       
       protected abstract void dataChanged(String path, Type eventType, String data);
   }
   ```
   The new curator API for listening node should implements CuratorCacheListener, and this method add new parameters.
    - ChildData oldData : is the snapshot of the old node data 
    -  ChildData data : is the new node data
    If the type is NODE_DELETED, the data will be null, and will be filtered.
   So, we have made the updates below:
   ```
   public abstract class AbstractJobListener implements CuratorCacheListener {
       
       @Override
       public final void event(final Type type, final ChildData oldData, final ChildData newData) {
           if (null == newData && null == oldData) {
               return;
           }
           String path = Type.NODE_DELETED == type ? oldData.getPath() : newData.getPath();
           byte[] data = Type.NODE_DELETED == type ? oldData.getData() : newData.getData();
           if (path.isEmpty()) {
               return;
           }
           dataChanged(path, type, null == data ? "" : new String(data, Charsets.UTF_8));
       }
       
       protected abstract void dataChanged(String path, Type eventType, String data);
   }
   ```


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org