use of java.util.regex.Pattern in project kafka by apache.
the class TopologyBuilderTest method testAddMoreThanOnePatternSourceNode.
@Test
public void testAddMoreThanOnePatternSourceNode() {
final TopologyBuilder builder = new TopologyBuilder();
Pattern expectedPattern = Pattern.compile("topics[A-Z]|.*-\\d");
builder.addSource("source-1", Pattern.compile("topics[A-Z]"));
builder.addSource("source-2", Pattern.compile(".*-\\d"));
assertEquals(expectedPattern.pattern(), builder.sourceTopicPattern().pattern());
}
use of java.util.regex.Pattern in project kafka by apache.
the class TopologyBuilderTest method shouldAddPatternSourceWithoutOffsetReset.
@Test
public void shouldAddPatternSourceWithoutOffsetReset() {
final TopologyBuilder builder = new TopologyBuilder();
final Serde<String> stringSerde = Serdes.String();
final Pattern expectedPattern = Pattern.compile("test-.*");
builder.addSource("source", stringSerde.deserializer(), stringSerde.deserializer(), Pattern.compile("test-.*"));
assertEquals(expectedPattern.pattern(), builder.sourceTopicPattern().pattern());
assertEquals(builder.earliestResetTopicsPattern().pattern(), "");
assertEquals(builder.latestResetTopicsPattern().pattern(), "");
}
use of java.util.regex.Pattern in project qpid by apache.
the class QpidQueueStats method main.
/**
* Runs QpidQueueStats.
* @param args the command line arguments.
*/
public static void main(final String[] args) {
String logLevel = System.getProperty("amqj.logging.level");
// Set default log level to FATAL rather than DEBUG.
logLevel = (logLevel == null) ? "FATAL" : logLevel;
System.setProperty("amqj.logging.level", logLevel);
String[] longOpts = { "help", "broker-address=", "filter=", "sasl-mechanism=" };
try {
String host = "localhost";
String connectionOptions = "{reconnect: true}";
List<Pattern> filter = new ArrayList<Pattern>();
GetOpt getopt = new GetOpt(args, "ha:f:", longOpts);
List<String[]> optList = getopt.getOptList();
for (String[] opt : optList) {
if (opt[0].equals("-h") || opt[0].equals("--help")) {
System.out.println(_usage);
System.out.println(_options);
System.exit(1);
} else if (opt[0].equals("-a") || opt[0].equals("--broker-address")) {
host = opt[1];
} else if (opt[0].equals("-f") || opt[0].equals("--filter")) {
String[] split = opt[1].split(",");
for (String s : split) {
Pattern p = Pattern.compile(s);
filter.add(p);
}
} else if (opt[0].equals("--sasl-mechanism")) {
connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
}
}
QpidQueueStats queueStats = new QpidQueueStats(host, connectionOptions, filter);
} catch (IllegalArgumentException e) {
System.out.println(_usage);
System.out.println(e.getMessage());
System.exit(1);
}
BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
try {
// Blocks here until return is pressed
String s = commandLine.readLine();
System.exit(0);
} catch (IOException e) {
System.out.println("QpidQueueStats main(): IOException: " + e.getMessage());
}
}
use of java.util.regex.Pattern in project qpid by apache.
the class QueueFuse method onEvent.
/**
* Main Event handler.
* @param wi a QMF2 WorkItem object
*/
public void onEvent(final WorkItem wi) {
if (wi instanceof EventReceivedWorkItem) {
EventReceivedWorkItem item = (EventReceivedWorkItem) wi;
Agent agent = item.getAgent();
QmfEvent event = item.getEvent();
String className = event.getSchemaClassId().getClassName();
if (className.equals("queueDeclare")) {
updateQueueCache();
} else if (className.equals("queueThresholdExceeded")) {
String queueName = event.getStringValue("qName");
boolean matches = false;
for (Pattern x : _filter) {
// Check the queue name against the regexes in the filter List (if any)
Matcher m = x.matcher(queueName);
if (m.find()) {
matches = true;
break;
}
}
if (_filter.isEmpty() || matches) {
// If there's no filter enabled or the filter matches the queue name we call purgeQueue().
long msgDepth = event.getLongValue("msgDepth");
purgeQueue(queueName, msgDepth);
}
}
}
}
use of java.util.regex.Pattern in project hive by apache.
the class GenericUDFRegExp method evaluate.
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
String s = getStringValue(arguments, 0, converters);
if (s == null) {
return null;
}
String regex;
if (isRegexConst) {
regex = regexConst;
} else {
regex = getStringValue(arguments, 1, converters);
}
if (regex == null) {
return null;
}
if (regex.length() == 0) {
if (!warned) {
warned = true;
LOG.warn(getClass().getSimpleName() + " regex is empty. Additional " + "warnings for an empty regex will be suppressed.");
}
output.set(false);
return output;
}
Pattern p;
if (isRegexConst) {
p = patternConst;
} else {
p = Pattern.compile(regex);
}
Matcher m = p.matcher(s);
output.set(m.find(0));
return output;
}
Aggregations