Search in sources :

Example 1 with UserAgentAnalyzerBuilder

use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.

the class UserAgentDissector method prepareForRun.

@Override
public void prepareForRun() {
    // Build the internal datastructures
    LOG.info("Preparing UserAgentAnalyzer to extract {}", requestedFieldNames.isEmpty() ? "all fields" : requestedFieldNames);
    final UserAgentAnalyzerBuilder builder = getUserAgentAnalyzerBuilder();
    extraResources.forEach(r -> LOG.warn("Loading extra resource: {}", r));
    extraResources.forEach(builder::addResources);
    requestedFieldNames.forEach(builder::withField);
    setupUserAgentAnalyzer();
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder)

Example 2 with UserAgentAnalyzerBuilder

use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.

the class ParseUserAgent method initialize.

private void initialize() {
    if (!initialized) {
        UserAgentAnalyzerBuilder analyzerBuilder = UserAgentAnalyzer.newBuilder().hideMatcherLoadStats().delayInitialization();
        if (cacheSize >= 0) {
            analyzerBuilder.withCache(cacheSize);
        }
        if (!requestedFields.isEmpty()) {
            for (String requestedField : requestedFields) {
                analyzerBuilder.withField(requestedField);
            }
        }
        analyzer = analyzerBuilder.build();
        if (requestedFields.isEmpty()) {
            requestedFields.addAll(analyzer.getAllPossibleFieldNamesSorted());
        }
        initialized = true;
    }
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder)

Example 3 with UserAgentAnalyzerBuilder

use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.

the class TestBuilder method createWithWantedFieldNames.

private UserAgentAnalyzer createWithWantedFieldNames(String... fieldNames) {
    UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder().dropTests().hideMatcherLoadStats();
    for (String fieldName : fieldNames) {
        builder.withField(fieldName);
    }
    UserAgentAnalyzer userAgentAnalyzer = builder.build();
    Set<String> wantedFieldNames = userAgentAnalyzer.getWantedFieldNames();
    LOG.info("Input : fields({}): {}", fieldNames.length, fieldNames);
    LOG.info("Output: fields({}): {}", wantedFieldNames == null ? "null" : wantedFieldNames.size(), wantedFieldNames);
    return userAgentAnalyzer;
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer)

Example 4 with UserAgentAnalyzerBuilder

use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.

the class AbstractSerializationTest method serializeAndDeserializeUAA.

private void serializeAndDeserializeUAA(boolean immediate, boolean runTestsBefore) throws IOException, ClassNotFoundException {
    LOG.info("==============================================================");
    LOG.info("Create");
    LOG.info("--------------------------------------------------------------");
    UserAgentAnalyzerBuilder uaab = UserAgentAnalyzer.newBuilder().keepTests().withCacheInstantiator(new TestingCacheInstantiator()).withCache(1234).hideMatcherLoadStats();
    if (immediate) {
        uaab.immediateInitialization();
    }
    UserAgentAnalyzer uaaBefore = uaab.build();
    String uaaBeforeString = uaaBefore.toString();
    if (runTestsBefore) {
        LOG.info("--------------------------------------------------------------");
        uaaBefore.getTestCases().forEach(testCase -> assertTrue(testCase.verify(uaaBefore)));
        // Get rid of the data of the last tested useragent
        uaaBefore.reset();
        String uaaBeforeAfterTestsString = uaaBefore.toString();
        assertEquals(uaaBeforeString, uaaBeforeAfterTestsString);
    }
    LOG.info("--------------------------------------------------------------");
    LOG.info("Serialize");
    long serializeStartNs = System.nanoTime();
    byte[] bytes = serialize(uaaBefore);
    long serializeStopNs = System.nanoTime();
    LOG.info("Serialize took {} ns ({} ms)", serializeStopNs - serializeStartNs, (serializeStopNs - serializeStartNs) / 1_000_000);
    LOG.info("The UserAgentAnalyzer was serialized into {} bytes", bytes.length);
    LOG.info("--------------------------------------------------------------");
    LOG.info("Deserialize");
    long deserializeStartNs = System.nanoTime();
    UserAgentAnalyzer uaaAfter = deserialize(bytes);
    long deserializeStopNs = System.nanoTime();
    LOG.info("Done");
    LOG.info("Deserialize took {} ns ({} ms)", deserializeStopNs - deserializeStartNs, (deserializeStopNs - deserializeStartNs) / 1_000_000);
    String uaaAfterString = uaaAfter.toString();
    assertEquals(uaaBeforeString, uaaAfterString);
    assertEquals(1234, uaaAfter.getCacheSize());
    LOG.info("==============================================================");
    LOG.info("Validating when getting all fields");
    LOG.info("--------------------------------------------------------------");
    uaaBefore.getTestCases().forEach(testCase -> assertTrue(testCase.verify(uaaBefore)));
    LOG.info("==============================================================");
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer)

Example 5 with UserAgentAnalyzerBuilder

use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.

the class TestBuilder method testDualBuilderUsageUseSetterAfterBuild.

@Test
void testDualBuilderUsageUseSetterAfterBuild() {
    UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder().delayInitialization();
    assertNotNull(builder.build(), "We should get a first instance from a single builder.");
    // And calling a setter after the build() should fail with an exception
    assertThrows(IllegalStateException.class, () -> builder.withCache(1234));
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

UserAgentAnalyzerBuilder (nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder)9 UserAgentAnalyzer (nl.basjes.parse.useragent.UserAgentAnalyzer)3 Test (org.junit.jupiter.api.Test)3 ArrayList (java.util.ArrayList)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)1