paul-rogers commented on a change in pull request #2044: DRILL-7678: Update Yauaa Dependency URL: https://github.com/apache/drill/pull/2044#discussion_r402067486
########## File path: contrib/udfs/src/main/java/org/apache/drill/exec/udfs/UserAgentAnalyzerProvider.java ########## @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.drill.exec.udfs; + +import nl.basjes.parse.useragent.UserAgentAnalyzer; + +public class UserAgentAnalyzerProvider { + + public static UserAgentAnalyzer getInstance() { + return UserAgentAnalyzerHolder.INSTANCE; + } + + private static class UserAgentAnalyzerHolder { + private static final UserAgentAnalyzer INSTANCE = UserAgentAnalyzer.newBuilder() Review comment: Did a little experiment to see if I was confused. Looks like a single layer of provider will work fine. Two classes: ``` public class DummyProvider { private static int instance = 10; static { System.out.println("DummyProvider loaded"); } public static int instance() { return instance; } } ``` And: ``` public class DummyClient { public static void main(String[] args) { System.out.println("Main starting"); System.out.println("Getting instance"); System.out.println(DummyProvider.instance()); System.out.println("Exiting"); } } ``` Output: ``` Main starting Getting instance DummyProvider loaded 10 Exiting ``` Ran in both the debugger and normally. Both produced the same output. This suggests that, indeed, the class is not loaded, and statics initialized, until first use (call). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
