@Override public boolean test(final Object first, final Collection second) { return first instanceof Number ? IteratorUtils.anyMatch(second.iterator(), o -> Compare.eq.test(first, o)) : second.contains(first); } },
@Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { // if this happens enough times (like the client is unable to deserialize a response) the pending // messages queue will not clear. wonder if there is some way to cope with that. of course, if // there are that many failures someone would take notice and hopefully stop the client. logger.error("Could not process the response", cause); // the channel took an error because of something pretty bad so release all the futures out there pending.values().forEach(val -> val.markError(cause)); pending.clear(); // serialization exceptions should not close the channel - that's worth a retry if (!IteratorUtils.anyMatch(ExceptionUtils.getThrowableList(cause).iterator(), t -> t instanceof SerializationException)) if (ctx.channel().isActive()) ctx.close(); }
/** * Remove a key from the parameter set. * * @param key the key to remove * @return the value of the removed key */ public Object remove(final Object key) { final List<Object> o = parameters.remove(key); // once a key is removed, it's possible that the traversal/label cache will need to be regenerated if (IteratorUtils.anyMatch(o.iterator(), p -> p instanceof Traversal.Admin)) { traversals.clear(); traversals = new ArrayList<>(); for (final List<Object> list : this.parameters.values()) { for (final Object object : list) { if (object instanceof Traversal.Admin) { final Traversal.Admin t = (Traversal.Admin) object; addTraversal(t); } } } } return o; }
return hasStepOfAssignableClassRecursively(stepClasses.iterator().next(), traversal); for (final Step<?, ?> step : traversal.getSteps()) { if (IteratorUtils.anyMatch(stepClasses.iterator(), stepClass -> stepClass.isAssignableFrom(step.getClass()))) { return true;
public DriverRemoteConnection(final Configuration conf) { final boolean hasClusterConf = IteratorUtils.anyMatch(conf.getKeys(), k -> k.startsWith("clusterConfiguration")); if (conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && hasClusterConf) throw new IllegalStateException(String.format("A configuration should not contain both '%s' and 'clusterConfiguration'", GREMLIN_REMOTE_DRIVER_CLUSTERFILE)); remoteTraversalSourceName = conf.getString(GREMLIN_REMOTE_DRIVER_SOURCENAME, DEFAULT_TRAVERSAL_SOURCE); try { final Cluster cluster; if (!conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && !hasClusterConf) cluster = Cluster.open(); else cluster = conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) ? Cluster.open(conf.getString(GREMLIN_REMOTE_DRIVER_CLUSTERFILE)) : Cluster.open(conf.subset("clusterConfiguration")); client = cluster.connect(Client.Settings.build().create()).alias(remoteTraversalSourceName); } catch (Exception ex) { throw new IllegalStateException(ex); } attachElements = false; tryCloseCluster = true; tryCloseClient = true; this.conf = Optional.of(conf); }
protected Optional<ThrowingConsumer<Context>> validateEvalMessage(final RequestMessage message) throws OpProcessorException { if (!message.optionalArgs(Tokens.ARGS_GREMLIN).isPresent()) { final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", Tokens.OPS_EVAL, Tokens.ARGS_GREMLIN); throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); } if (message.optionalArgs(Tokens.ARGS_BINDINGS).isPresent()) { final Map bindings = (Map) message.getArgs().get(Tokens.ARGS_BINDINGS); if (IteratorUtils.anyMatch(bindings.keySet().iterator(), k -> null == k || !(k instanceof String))) { final String msg = String.format("The [%s] message is using one or more invalid binding keys - they must be of type String and cannot be null", Tokens.OPS_EVAL); throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); } final Set<String> badBindings = IteratorUtils.set(IteratorUtils.<String>filter(bindings.keySet().iterator(), INVALID_BINDINGS_KEYS::contains)); if (!badBindings.isEmpty()) { final String msg = String.format("The [%s] message supplies one or more invalid parameters key of [%s] - these are reserved names.", Tokens.OPS_EVAL, badBindings); throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); } // ignore control bindings that get passed in with the "#jsr223" prefix - those aren't used in compilation if (IteratorUtils.count(IteratorUtils.filter(bindings.keySet().iterator(), k -> !k.toString().startsWith("#jsr223"))) > maxParameters) { final String msg = String.format("The [%s] message contains %s bindings which is more than is allowed by the server %s configuration", Tokens.OPS_EVAL, bindings.size(), maxParameters); throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); } } return Optional.empty(); }
@Override public boolean test(final Object first, final Collection second) { return first instanceof Number ? IteratorUtils.anyMatch(second.iterator(), o -> Compare.eq.test(first, o)) : second.contains(first); } },
@Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { // if this happens enough times (like the client is unable to deserialize a response) the pending // messages queue will not clear. wonder if there is some way to cope with that. of course, if // there are that many failures someone would take notice and hopefully stop the client. logger.error("Could not process the response", cause); // the channel took an error because of something pretty bad so release all the futures out there pending.values().forEach(val -> val.markError(cause)); pending.clear(); // serialization exceptions should not close the channel - that's worth a retry if (!IteratorUtils.anyMatch(ExceptionUtils.getThrowableList(cause).iterator(), t -> t instanceof SerializationException)) if (ctx.channel().isActive()) ctx.close(); }
/** * Remove a key from the parameter set. * * @param key the key to remove * @return the value of the removed key */ public Object remove(final Object key) { final List<Object> o = parameters.remove(key); // once a key is removed, it's possible that the traversal/label cache will need to be regenerated if (IteratorUtils.anyMatch(o.iterator(), p -> p instanceof Traversal.Admin)) { traversals.clear(); traversals = new ArrayList<>(); for (final List<Object> list : this.parameters.values()) { for (final Object object : list) { if (object instanceof Traversal.Admin) { final Traversal.Admin t = (Traversal.Admin) object; addTraversal(t); } } } } return o; }
return hasStepOfAssignableClassRecursively(stepClasses.iterator().next(), traversal); for (final Step<?, ?> step : traversal.getSteps()) { if (IteratorUtils.anyMatch(stepClasses.iterator(), stepClass -> stepClass.isAssignableFrom(step.getClass()))) { return true;
public DriverRemoteConnection(final Configuration conf) { final boolean hasClusterConf = IteratorUtils.anyMatch(conf.getKeys(), k -> k.startsWith("clusterConfiguration")); if (conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && hasClusterConf) throw new IllegalStateException(String.format("A configuration should not contain both '%s' and 'clusterConfiguration'", GREMLIN_REMOTE_DRIVER_CLUSTERFILE)); remoteTraversalSourceName = conf.getString(GREMLIN_REMOTE_DRIVER_SOURCENAME, DEFAULT_TRAVERSAL_SOURCE); try { final Cluster cluster; if (!conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && !hasClusterConf) cluster = Cluster.open(); else cluster = conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) ? Cluster.open(conf.getString(GREMLIN_REMOTE_DRIVER_CLUSTERFILE)) : Cluster.open(conf.subset("clusterConfiguration")); client = cluster.connect(Client.Settings.build().create()).alias(remoteTraversalSourceName); } catch (Exception ex) { throw new IllegalStateException(ex); } tryCloseCluster = true; tryCloseClient = true; this.conf = Optional.of(conf); }
protected Optional<ThrowingConsumer<Context>> validateEvalMessage(final RequestMessage message) throws OpProcessorException { if (!message.optionalArgs(Tokens.ARGS_GREMLIN).isPresent()) { final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", Tokens.OPS_EVAL, Tokens.ARGS_GREMLIN); throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); } if (message.optionalArgs(Tokens.ARGS_BINDINGS).isPresent()) { final Map bindings = (Map) message.getArgs().get(Tokens.ARGS_BINDINGS); if (IteratorUtils.anyMatch(bindings.keySet().iterator(), k -> null == k || !(k instanceof String))) { final String msg = String.format("The [%s] message is using one or more invalid binding keys - they must be of type String and cannot be null", Tokens.OPS_EVAL); throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); } final Set<String> badBindings = IteratorUtils.set(IteratorUtils.<String>filter(bindings.keySet().iterator(), INVALID_BINDINGS_KEYS::contains)); if (!badBindings.isEmpty()) { final String msg = String.format("The [%s] message supplies one or more invalid parameters key of [%s] - these are reserved names.", Tokens.OPS_EVAL, badBindings); throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); } // ignore control bindings that get passed in with the "#jsr223" prefix - those aren't used in compilation if (IteratorUtils.count(IteratorUtils.filter(bindings.keySet().iterator(), k -> !k.toString().startsWith("#jsr223"))) > maxParameters) { final String msg = String.format("The [%s] message contains %s bindings which is more than is allowed by the server %s configuration", Tokens.OPS_EVAL, bindings.size(), maxParameters); throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); } } return Optional.empty(); }