当前位置: 首页>>代码示例>>Java>>正文


Java FunctionAdapter类代码示例

本文整理汇总了Java中com.gemstone.gemfire.cache.execute.FunctionAdapter的典型用法代码示例。如果您正苦于以下问题:Java FunctionAdapter类的具体用法?Java FunctionAdapter怎么用?Java FunctionAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FunctionAdapter类属于com.gemstone.gemfire.cache.execute包,在下文中一共展示了FunctionAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerFunction

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void registerFunction() {
  FunctionService.registerFunction(new FunctionAdapter() {
    @Override
    public void execute(FunctionContext context) {
      if (context.getArguments() instanceof String) {
        context.getResultSender().lastResult("Failure");
      }
      else if (context.getArguments() instanceof Boolean) {
        context.getResultSender().lastResult(Boolean.FALSE);
      }
    }

    @Override
    public String getId() {
      return "Function";
    }

    @Override
    public boolean hasResult() {
      return true;
    }
  });
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:24,代码来源:MemberFunctionExecutionDUnitTest.java

示例2: executeInlineFunction

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void executeInlineFunction() {
  List list = (List)FunctionService.onRegion(region).withArgs(Boolean.TRUE)
      .execute(new FunctionAdapter() {
        @Override
        public void execute(FunctionContext context) {
          if (context.getArguments() instanceof String) {
            context.getResultSender().lastResult("Success");
          }
          else if (context.getArguments() instanceof Boolean) {
            context.getResultSender().lastResult(Boolean.TRUE);
          }
        }

        @Override
        public String getId() {
          return "Function";
        }

        @Override
        public boolean hasResult() {
          return true;
        }
      }).getResult();
  assertEquals(1, list.size());
  assertEquals(Boolean.TRUE, list.get(0));
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:27,代码来源:DistributedRegionFunctionExecutionDUnitTest.java

示例3: registerFunction

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void registerFunction() {
  FunctionService.registerFunction(new FunctionAdapter() {
    @Override
    public void execute(FunctionContext context) {
      if (context.getArguments() instanceof String) {
        context.getResultSender().lastResult("Failure");
      }
      else if (context.getArguments() instanceof Boolean) {
         context.getResultSender().lastResult(Boolean.FALSE);
      }
    }

    @Override
    public String getId() {
      return "Function";
    }

    @Override
    public boolean hasResult() {
      return true;
    }
  });
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:24,代码来源:DistributedRegionFunctionExecutionDUnitTest.java

示例4: registerFunction

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void registerFunction() {
  FunctionService.registerFunction(new FunctionAdapter() {
    public void execute(FunctionContext context) {
      if (context.getArguments() instanceof String) {
        context.getResultSender().lastResult("Failure");
      }
      else if (context.getArguments() instanceof Boolean) {
        context.getResultSender().lastResult(Boolean.FALSE);
      }
    }

    public String getId() {
      return "Function";
    }

    public boolean hasResult() {
      return true;
    }
  });
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:21,代码来源:ClientServerFunctionExecutionDUnitTest.java

示例5: FunctionExecution_Inline_Bug40714

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void FunctionExecution_Inline_Bug40714() {
  DistributedSystem.setThreadsSocketPolicy(false);
  Execution member = FunctionService.onServers(pool);
  try {
    ResultCollector rs = member.withArgs(Boolean.TRUE).execute(
        new FunctionAdapter() {
          public void execute(FunctionContext context) {
            if (context.getArguments() instanceof String) {
              context.getResultSender().lastResult("Success");
            }
            else if (context.getArguments() instanceof Boolean) {
              context.getResultSender().lastResult(Boolean.TRUE);
            }
          }

          public String getId() {
            return "Function";
          }

          public boolean hasResult() {
            return true;
          }
        });
    List resultList = (List)rs.getResult();
    assertEquals(3, resultList.size());
    assertEquals(Boolean.TRUE, resultList.get(0));
    assertEquals(Boolean.TRUE, resultList.get(1));
    assertEquals(Boolean.TRUE, resultList.get(2));

  }
  catch (Exception ex) {
    ex.printStackTrace();
    getLogWriter().info("Exception : ", ex);
    fail("Test failed after the execute operation.");
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:37,代码来源:ClientServerFunctionExecutionDUnitTest.java

示例6: serverExecution_Inline

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void serverExecution_Inline() {
  
  DistributedSystem.setThreadsSocketPolicy(false);
  Execution member = FunctionService.onServer(pool);
      
  try {
    ResultCollector rs = member.withArgs(Boolean.TRUE).execute(new FunctionAdapter(){
      public void execute(FunctionContext context) {
        if (context.getArguments() instanceof String) {
          context.getResultSender().lastResult( "Success");
        }else if(context.getArguments() instanceof Boolean){
          context.getResultSender().lastResult( Boolean.TRUE);
        }
      }

      public String getId() {
        return getClass().getName();
      }

      public boolean hasResult() {
        return true;
      }
    });      
    assertEquals(Boolean.TRUE, ((List)rs.getResult()).get(0));
    
  }catch (Exception ex) {
    ex.printStackTrace();
    getLogWriter().info("Exception : " , ex);
    fail("Test failed after the execute operation nn TRUE");
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:32,代码来源:ClientServerFunctionExecutionDUnitTest.java

示例7: serverExecution_Inline_InvalidAttributes

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void serverExecution_Inline_InvalidAttributes() {
  
  DistributedSystem.setThreadsSocketPolicy(false);
  Execution member = FunctionService.onServer(pool);
      
  try {
    ResultCollector rs = member.withArgs(Boolean.TRUE).execute(new FunctionAdapter(){
      public void execute(FunctionContext context) {
        if (context.getArguments() instanceof String) {
          context.getResultSender().lastResult( "Success");
        }else if(context.getArguments() instanceof Boolean){
          context.getResultSender().lastResult( Boolean.TRUE);
        }
      }

      public String getId() {
        return getClass().getName();
      }

      public boolean hasResult() {
        return false;
      }
      public boolean isHA(){
        return true;
      }
    });      
    
    fail("Should have failed with Invalid attributes.");
    
  }catch (Exception ex) {
    getLogWriter().info("Exception : " , ex);
    assertTrue(ex.getMessage().contains(
        "For Functions with isHA true, hasResult must also be true."));
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:36,代码来源:ClientServerFunctionExecutionDUnitTest.java

示例8: allServerExecution_Inline

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void allServerExecution_Inline() {
  DistributedSystem.setThreadsSocketPolicy(false);
  Execution member = FunctionService.onServers(pool);
  try {
    ResultCollector rs = member.withArgs(Boolean.TRUE).execute(new FunctionAdapter(){
      public void execute(FunctionContext context) {
        if (context.getArguments() instanceof String) {
          context.getResultSender().lastResult( "Success");
        }else if(context.getArguments() instanceof Boolean){
          context.getResultSender().lastResult( Boolean.TRUE);
        }
      }

      public String getId() {
        return getClass().getName();
      }

      public boolean hasResult() {
        return true;
      }
    });  
    List resultList = (List)rs.getResult();
    assertEquals(Boolean.TRUE, resultList.get(0));
    assertEquals(Boolean.TRUE, resultList.get(1));
    assertEquals(Boolean.TRUE, resultList.get(2));
         
  }catch (Exception ex) {
    ex.printStackTrace();
    getLogWriter().info("Exception : " , ex);
    fail("Test failed after the execute operation asdfasdfa   ");
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:33,代码来源:ClientServerFunctionExecutionDUnitTest.java

示例9: execFireNForget

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
private void execFireNForget() {
  Execution dataSet;
  FireAndForgetFunction ffFunction = null;
  List argumentList = new ArrayList();

  dataSet = getExecutionObject();
  argumentList.add(RemoteTestModule.getCurrentThread().getThreadId());
  // Dont care about filter
  try {
    logInfo(opPrefix + "Starting execution of ffFunction "
        + ffFunction.getId());
    ResultCollector drc = dataSet.withArgs(argumentList).execute(
        new FunctionAdapter() {
          @Override
          public String getId() {
            return "" + hashCode();
          }

          @Override
          public void execute(FunctionContext context) {
            Log.getLogWriter().info(
                opPrefix + "Invoking fire and forget onMembers() function");
            ArrayList list = new ArrayList();
            DistributionConfig dc = ((InternalDistributedSystem) InternalDistributedSystem
                .getAnyInstance()).getConfig();
            list.add(dc.getCacheXmlFile());
            Log.getLogWriter().info(opPrefix + "Updating the BB list");
          }
        });
    opRecorder.functionExecuted("FIRENFORGET", null);
    logInfo(opPrefix + "Finished execution of ffFunction "
        + ffFunction.getId());
  } catch (Exception e) {
    logInfo(opPrefix + "Error running function " + e.getMessage());
    throw new TestException(TestHelper.getStackTrace(e));
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:38,代码来源:FunctionOperations.java

示例10: randomFunctionExecution

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
/**
 * 
 * Task to execute functions
 */
public static ResultCollector randomFunctionExecution(Execution dataSet,
    FunctionAdapter function) {
  try {
    Log.getLogWriter().info("Called final execute function");
    ResultCollector drc = dataSet.execute(function);
    // drc.getResult();
    return drc;
  }
  catch (Exception e) {
    throw new TestException("Got this exception during execute operation ", e);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:17,代码来源:FunctionServiceTest.java

示例11: bug41118

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void bug41118(){
  ds = new MemberFunctionExecutionDUnitTest("temp").getSystem();
  assertNotNull(ds);
  ds.disconnect();
  Properties props = new Properties();
  props.setProperty("mcast-port", "0");
  ds = (InternalDistributedSystem)DistributedSystem.connect(props);
  
  DM dm = ds.getDistributionManager();
  assertEquals("Distributed System is not loner", true, dm instanceof LonerDistributionManager);
  
  DistributedMember localmember = ds.getDistributedMember();
  Execution memberExcution = null;
  memberExcution = FunctionService.onMember(ds,localmember);  
  Execution executor = memberExcution.withArgs("Key");
  try {
    ResultCollector rc = executor.execute(new FunctionAdapter(){
      @Override
      public void execute(FunctionContext context) {
        if (context.getArguments() instanceof String) {
          context.getResultSender().lastResult("Success");
        }else{
          context.getResultSender().lastResult("Failure");
        }
      }

      @Override
      public String getId() {
        return getClass().getName();
      }

      @Override
      public boolean hasResult() {
        return true;
      }
    });
    List li = (ArrayList)rc.getResult();
    getLogWriter().info(
        "MemberFunctionExecutionDUnitTest#excuteOnMembers: Result : " + li);
    assertEquals(li.size(), 1);
    for (Object obj : li) {
      assertEquals(obj, "Success");
    }
    ds.disconnect();
  }
  catch (Exception e) {
    getLogWriter().info("Exception Occured : "+ e.getMessage());
    e.printStackTrace();
    fail("Test failed",e);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:52,代码来源:MemberFunctionExecutionDUnitTest.java

示例12: excuteOnMembers_InlineFunction

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void excuteOnMembers_InlineFunction(Integer noOfMembers) {
  assertNotNull(ds);
  Execution memberExcution = null;
  if(noOfMembers.intValue() == 1){  //Local VM
    DistributedMember localmember = ds.getDistributedMember();
    memberExcution = FunctionService.onMember(ds,localmember);  
  }
  else if(noOfMembers.intValue() == 5){
    memberExcution = FunctionService.onMembers(ds);
  }else{
    Set memberSet = new HashSet(ds.getDistributionManager().getNormalDistributionManagerIds());
    InternalDistributedMember localVM = ds.getDistributionManager().getDistributionManagerId();
    memberSet.remove(localVM);
    memberExcution = FunctionService.onMembers(ds,memberSet);
  }
  Execution executor = memberExcution.withArgs("Key");
  try {
    ResultCollector rc = executor.execute(new FunctionAdapter(){
      @Override
      public void execute(FunctionContext context) {
        if (context.getArguments() instanceof String) {
          context.getResultSender().lastResult("Success");
        }else{
          context.getResultSender().lastResult("Failure");
        }
      }

      @Override
      public String getId() {
        return getClass().getName();
      }

      @Override
      public boolean hasResult() {
        return true;
      }
    });
    List li = (ArrayList)rc.getResult();
    getLogWriter().info(
        "MemberFunctionExecutionDUnitTest#excuteOnMembers: Result : " + li);
    assertEquals(li.size(), noOfMembers.intValue());
    for (Object obj : li) {
      assertEquals(obj, "Success");
    }
  }
  catch (Exception e) {
    getLogWriter().info("Exception Occured : "+ e.getMessage());
    e.printStackTrace();
    fail("Test failed",e);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:52,代码来源:MemberFunctionExecutionDUnitTest.java

示例13: bug41118

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void bug41118(){
  InternalDistributedSystem ds = new PRFunctionExecutionDUnitTest("temp").getSystem();
  assertNotNull(ds);
  ds.disconnect();
  Properties props = new Properties();
  props.setProperty("mcast-port", "0");
  ds = (InternalDistributedSystem)DistributedSystem.connect(props);
  
  DM dm = ds.getDistributionManager();
  assertEquals("Distributed System is not loner", true, dm instanceof LonerDistributionManager);
  
  Cache cache = CacheFactory.create(ds);
  AttributesFactory factory = new AttributesFactory();
  factory.setDataPolicy(DataPolicy.PARTITION);
  assertNotNull(cache);
  Region region = cache.createRegion("PartitonedRegion", factory.create());
  for (int i = 0; i < 20; i++) {
    region.put("KEY_" + i, "VALUE_" + i);
  }
  Set<String> keysForGet = new HashSet<String>();
  keysForGet.add("KEY_4");
  keysForGet.add("KEY_9");
  keysForGet.add("KEY_7");
  try {
    Execution execution = FunctionService.onRegion(region).withFilter(
        keysForGet).withArgs(Boolean.TRUE);
    ResultCollector rc = execution.execute(new FunctionAdapter() {
      @Override
      public void execute(FunctionContext fc) {
        RegionFunctionContext context = (RegionFunctionContext)fc;
        Set keys = context.getFilter();
        Set keysTillSecondLast = new HashSet();
        int setSize = keys.size();
        Iterator keysIterator = keys.iterator();
        for (int i = 0; i < (setSize - 1); i++) {
          keysTillSecondLast.add(keysIterator.next());
        }
        for (Object k : keysTillSecondLast) {
          context.getResultSender().sendResult(
              (Serializable)PartitionRegionHelper.getLocalDataForContext(
                  context).get(k));
        }
        Object lastResult = keysIterator.next();
        context.getResultSender().lastResult(
            (Serializable)PartitionRegionHelper.getLocalDataForContext(
                context).get(lastResult));
      }

      @Override
      public String getId() {
        return getClass().getName();
      }
    });
    rc.getResult();
    ds.disconnect();
  }
  catch (Exception e) {
    getLogWriter().info("Exception Occured : " + e.getMessage());
    e.printStackTrace();
    fail("Test failed", e);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:63,代码来源:PRFunctionExecutionDUnitTest.java

示例14: serverMultiKeyExecution_Inline

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void serverMultiKeyExecution_Inline() {
  Region region = cache.getRegion(PartitionedRegionName);
  assertNotNull(region);
  final HashSet testKeysSet = new HashSet();
  for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
    testKeysSet.add("execKey-" + i);
  }
  DistributedSystem.setThreadsSocketPolicy(false);
  Execution dataSet = FunctionService.onRegion(region);
  try {
    int j = 0;
    HashSet origVals = new HashSet();
    for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
      Integer val = new Integer(j++);
      origVals.add(val);
      region.put(i.next(), val);
    }
    List l = null;
    ResultCollector rc1 = dataSet.withFilter(testKeysSet).withArgs(Boolean.TRUE).execute(new FunctionAdapter(){
      @Override
      public void execute(FunctionContext context) {
        if (context.getArguments() instanceof String) {
          context.getResultSender().lastResult( "Success");
        }else if(context.getArguments() instanceof Boolean){
          context.getResultSender().lastResult(Boolean.TRUE);
        }          
      }

      @Override
      public String getId() {
        return getClass().getName();
      }

      @Override
      public boolean hasResult() {
        return true;
      }
    });
    l = ((List)rc1.getResult());
    getLogWriter().info("Result size : " + l.size());
    assertEquals(3, l.size());
    for (Iterator i = l.iterator(); i.hasNext();) {
      assertEquals(Boolean.TRUE, i.next());
    }
  }catch(Exception e){
    getLogWriter().info("Exception : " + e.getMessage());
    e.printStackTrace();
    fail("Test failed after the put operation");
    
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:52,代码来源:PRClientServerRegionFunctionExecutionDUnitTest.java

示例15: serverMultiKeyExecution_FunctionInvocationTargetException

import com.gemstone.gemfire.cache.execute.FunctionAdapter; //导入依赖的package包/类
public static void serverMultiKeyExecution_FunctionInvocationTargetException() {
  Region region = cache.getRegion(PartitionedRegionName);
  assertNotNull(region);
  final HashSet testKeysSet = new HashSet();
  for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
    testKeysSet.add("execKey-" + i);
  }
  DistributedSystem.setThreadsSocketPolicy(false);
  Execution dataSet = FunctionService.onRegion(region);
  int j = 0;
  HashSet origVals = new HashSet();
  for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
    Integer val = new Integer(j++);
    origVals.add(val);
    region.put(i.next(), val);
  }
  ResultCollector rc1 = null;
  try {
    rc1 = dataSet.withFilter(testKeysSet).withArgs(Boolean.TRUE).execute(
        new FunctionAdapter() {
          @Override
          public void execute(FunctionContext context) {
            if (((RegionFunctionContext)context).isPossibleDuplicate()) {
              context.getResultSender().lastResult(new Integer(retryCount));
              return;
            }
            if (context.getArguments() instanceof Boolean) {
              throw new FunctionInvocationTargetException(
                  "I have been thrown from TestFunction");
            }
          }
          @Override
          public String getId() {
            return getClass().getName();
          }

          @Override
          public boolean hasResult() {
            return true;
          }
        });

    List list = (ArrayList)rc1.getResult();
    assertEquals(list.get(0), 0);
  }
  catch (Throwable e) {
    e.printStackTrace();
    fail("This is not expected Exception", e);
  }

}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:52,代码来源:PRClientServerRegionFunctionExecutionDUnitTest.java


注:本文中的com.gemstone.gemfire.cache.execute.FunctionAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。