Author: jacopoc
Date: Tue Aug 26 08:02:29 2014
New Revision: 1620525
URL:
http://svn.apache.org/r1620525Log:
Small optimization: instead of calling the InetAddress.getLocalHost() method every time a Visit is created, do it once when the class is loaded.
Modified:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java?rev=1620525&r1=1620524&r2=1620525&view=diff==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java Tue Aug 26 08:02:29 2014
@@ -45,6 +45,17 @@ public class VisitHandler {
public static final String visitorCookieName = "OFBiz.Visitor";
+ private static final InetAddress address;
+ static {
+ InetAddress tmpAddress = null;
+ try {
+ tmpAddress = InetAddress.getLocalHost();
+ } catch (java.net.UnknownHostException e) {
+ Debug.logError("Unable to get server's internet address: " + e.toString(), module);
+ }
+ address = tmpAddress;
+ }
+
public static void setUserLogin(HttpSession session, GenericValue userLogin, boolean userCreated) {
if (userLogin == null) return;
ModelEntity modelUserLogin = userLogin.getModelEntity();
@@ -165,17 +176,11 @@ public class VisitHandler {
}
// get localhost ip address and hostname to store
- try {
- InetAddress address = InetAddress.getLocalHost();
- if (address != null) {
- visit.set("serverIpAddress", address.getHostAddress());
- visit.set("serverHostName", address.getHostName());
- } else {
- Debug.logError("Unable to get localhost internet address, was null", module);
- }
- } catch (java.net.UnknownHostException e) {
- Debug.logError("Unable to get localhost internet address: " + e.toString(), module);
+ if (address != null) {
+ visit.set("serverIpAddress", address.getHostAddress());
+ visit.set("serverHostName", address.getHostName());
}
+
try {
visit = delegator.createSetNextSeqId(visit);
session.setAttribute("visit", visit);