Search in sources :

Example 41 with Pattern

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());
}
Also used : Pattern(java.util.regex.Pattern) Test(org.junit.Test)

Example 42 with 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(), "");
}
Also used : Pattern(java.util.regex.Pattern) Test(org.junit.Test)

Example 43 with 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());
    }
}
Also used : GetOpt(org.apache.qpid.qmf2.util.GetOpt) Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 44 with Pattern

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);
            }
        }
    }
}
Also used : Agent(org.apache.qpid.qmf2.console.Agent) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) EventReceivedWorkItem(org.apache.qpid.qmf2.console.EventReceivedWorkItem) QmfEvent(org.apache.qpid.qmf2.common.QmfEvent)

Example 45 with Pattern

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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Aggregations

Pattern (java.util.regex.Pattern)2745 Matcher (java.util.regex.Matcher)1806 ArrayList (java.util.ArrayList)334 Test (org.junit.Test)209 IOException (java.io.IOException)206 File (java.io.File)172 HashMap (java.util.HashMap)144 Field (java.lang.reflect.Field)118 BufferedReader (java.io.BufferedReader)108 Map (java.util.Map)97 PatternSyntaxException (java.util.regex.PatternSyntaxException)97 List (java.util.List)81 HashSet (java.util.HashSet)69 InputStreamReader (java.io.InputStreamReader)59 FileInputStream (java.io.FileInputStream)40 InputStream (java.io.InputStream)39 FileReader (java.io.FileReader)36 SmallTest (android.test.suitebuilder.annotation.SmallTest)31 URL (java.net.URL)29 LinkedHashMap (java.util.LinkedHashMap)28