JSPservletPkg
Class Mapper

java.lang.Object
  |
  +--JSPservletPkg.Mapper

class Mapper
extends java.lang.Object
implements MapperIntf

Maps the user hostname. Version 1.0.4.

Copyright (c) 2000-2001

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 

Version:
1, 0, 4
Author:
Alexis Grandemange
See Also:
Cache, whoisHandler

Inner Class Summary
(package private)  class Mapper.Checker
          Checker thread class.
(package private)  class Mapper.whoisFailedSubscriber
          whois servers can be down...
 
Field Summary
(package private) static Region Asia
          Asia region.
(package private) static Region AsiaNames
          Asia region.
private static int CHECK
          Check availability - use of subscrib and rc.
(package private) static Mapper.Checker checker
          Checker object created in constructor.
(package private) static Region EMEA
          Europa, Middle East and Africa region.
(package private) static Region EMEAnames
          Europa, Middle East and Africa region.
private  JSPhandler handler
          Handle on JSPhandler.
(package private) static Region LatinAmerica
          Latin America region.
(package private) static Region LatinAmericaNames
          Latin America region.
(package private) static Region Misc
          We put there US, Canada and small isolated states.
(package private) static Region MiscNames
          We put there US, Canada and small isolated states.
private  java.lang.String msg
          Error - diagnosis message.
private static int NOOP
          No operation - wait.
(package private)  int num
          Number used for round-robbin load balancing.
(package private) static Region Ocean
          Pacific Ocean region.
(package private) static Region OceanNames
          Pacific ocean region.
private  java.lang.String publisher
          Publisher URL.
(package private) static Region[] regionNames
          List of non-generic name regions.
(package private) static Region[] regions
          List of non-generic code regions.
private  java.util.Map subscribers
          Key: domain.
Value: String[].
private  java.util.Map subscribersByCountry
          Key: country.
Value: String[].
private  java.util.Map subscribersByRegion
          Key: region.
Value: String[].
(package private) static Region Test
          For test purpose.
(package private) static Region TestNames
          For consistency...
(package private) static Region Unknown
          Generic name region.
(package private)  java.util.ArrayList whoisFailedSubscribers
          Stores whoisFailedSubscriber elements.
(package private) static whoisHandler whoisHdlr
          whoisHandler object created in constructor.
 
Constructor Summary
(package private) Mapper(java.lang.String publisher, JSPhandler handler)
          Constructor.
 
Method Summary
 boolean check(java.lang.String subscriber)
          Checks the state of a subscribing PageBox and updates its state.
 void checkAll(int counterForPing)
          Update global subscriber state.
At each loop the scanner thread increments the invocation number.
Allows to do 1/12 of the checks at a call.
(package private) static java.lang.String formatAddress(long add)
          Returns a readable IP address in usual xxx.xxx.xxx.xxx format.
 java.lang.String getDomain(java.lang.String host)
          Service method.
 java.lang.String getInfo()
          Returns info string.
(package private) static long getLongAddress(java.lang.String address)
          Converts the IP address in a number more suitable for comparison.
Validated with mapper.testRipe.
 java.lang.String getMessage()
          returns error - diagnosis message.
 java.lang.String getPageBox(java.lang.String domain, java.lang.String address)
          Returns the URL of the PageBox to use for a given URL.
private  boolean initialize()
          Version 1.0.4.
private  java.lang.String loadBalance(java.lang.String[] PageBoxes)
          Round-robbin load balancing returning a url.
private  void register(java.lang.String code, java.lang.String subscriber)
          Registers a PageBox in the proper country and region.
(package private)  void removeFromSubscribers(java.lang.String subscriber, java.lang.String domain)
          Cleanup subscribers for invalid subscribers.
private  java.lang.String[] scan(java.lang.String code)
          Given a country code returns: PageBoxes in the same country. If not found, PageBoxes in the same region.
private  java.lang.String search(java.lang.String address)
          Version 1.0.4.
private static whoisHandler.CodeRange whois(java.lang.String address)
          Version 1.0.4.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

EMEA

static final Region EMEA
Europa, Middle East and Africa region. Country code table.

Asia

static final Region Asia
Asia region. Country code table.

LatinAmerica

static final Region LatinAmerica
Latin America region. Country code table.

Ocean

static final Region Ocean
Pacific Ocean region. Country code table.

Misc

static final Region Misc
We put there US, Canada and small isolated states. Country code table.

EMEAnames

static final Region EMEAnames
Europa, Middle East and Africa region. Country name table. Indexes must match EMEA region.

AsiaNames

static final Region AsiaNames
Asia region. Country name table. Indexes must match Asia region.

LatinAmericaNames

static final Region LatinAmericaNames
Latin America region. Country name table. Indexes must match LatinAmerica region.

OceanNames

static final Region OceanNames
Pacific ocean region. Country name table. Indexes must match Ocean region.

MiscNames

static final Region MiscNames
We put there US, Canada and small isolated states. Country name table. Indexes must match LatinAmerica region.

Test

static final Region Test
For test purpose. AGRANDEM is my host name. Replace by yours...

TestNames

static final Region TestNames
For consistency... No whois server will be invoked.

Unknown

static final Region Unknown
Generic name region. Generic code table.

regions

static Region[] regions
List of non-generic code regions.

regionNames

static Region[] regionNames
List of non-generic name regions. Indexes must match regions array

subscribers

private java.util.Map subscribers
Key: domain.
Value: String[]. Subscribers.

subscribersByCountry

private java.util.Map subscribersByCountry
Key: country.
Value: String[]. Subscribers.

subscribersByRegion

private java.util.Map subscribersByRegion
Key: region.
Value: String[]. Subscribers.

publisher

private java.lang.String publisher
Publisher URL.

handler

private JSPhandler handler
Handle on JSPhandler.

checker

static Mapper.Checker checker
Checker object created in constructor.

whoisHdlr

static whoisHandler whoisHdlr
whoisHandler object created in constructor.

NOOP

private static final int NOOP
No operation - wait.

CHECK

private static final int CHECK
Check availability - use of subscrib and rc.

whoisFailedSubscribers

java.util.ArrayList whoisFailedSubscribers
Stores whoisFailedSubscriber elements.

msg

private java.lang.String msg
Error - diagnosis message.

num

int num
Number used for round-robbin load balancing.
Constructor Detail

Mapper

Mapper(java.lang.String publisher,
       JSPhandler handler)
Constructor.
Parameters:
publisher - publisher url.
handler - handle on JSPhandler.
Method Detail

getInfo

public java.lang.String getInfo()
Returns info string.
Specified by:
getInfo in interface MapperIntf

formatAddress

static java.lang.String formatAddress(long add)
Returns a readable IP address in usual xxx.xxx.xxx.xxx format.
Parameters:
add - numeric value.

checkAll

public void checkAll(int counterForPing)
Update global subscriber state.
At each loop the scanner thread increments the invocation number.
Allows to do 1/12 of the checks at a call.
Specified by:
checkAll in interface MapperIntf
Parameters:
counterForPing - invocation number.

check

public boolean check(java.lang.String subscriber)
Checks the state of a subscribing PageBox and updates its state.
Specified by:
check in interface MapperIntf
Parameters:
subscriber - subscribing PageBox.
Returns:
boolean true if PageBox is up.

initialize

private boolean initialize()
Version 1.0.4. Cache persistence + cache per code.

Initializes subscribers, subscribersByCountry, subscribersByRegion.
Validated with mapper.testInit.


register

private final void register(java.lang.String code,
                            java.lang.String subscriber)
Registers a PageBox in the proper country and region.
Parameters:
code - country code.
subscriber - subscribing PageBox.

removeFromSubscribers

void removeFromSubscribers(java.lang.String subscriber,
                           java.lang.String domain)
Cleanup subscribers for invalid subscribers.
Parameters:
subscriber - invalid subscriber.
domain - invalid subscriber domain.

getMessage

public java.lang.String getMessage()
returns error - diagnosis message.
Specified by:
getMessage in interface MapperIntf

getPageBox

public java.lang.String getPageBox(java.lang.String domain,
                                   java.lang.String address)
Returns the URL of the PageBox to use for a given URL.

Intented use: JSPservlet uses ServletRequest.getRemoteHost to get the name of the requestor and updates page HREF with the returned URL.

  1. Checks if there are PageBoxes in the same domain as requestor
  2. If the TLD is not a country code, calls whois
  3. Scan countries for PageBoxes
Specified by:
getPageBox in interface MapperIntf
Parameters:
domain - requestor domain.
address - requestor IP address.

scan

private java.lang.String[] scan(java.lang.String code)
Given a country code returns:
  1. PageBoxes in the same country.
  2. If not found, PageBoxes in the same region.
Parameters:
code - country code.

loadBalance

private final java.lang.String loadBalance(java.lang.String[] PageBoxes)
Round-robbin load balancing returning a url.
Parameters:
PageBoxes - candidate urls.

getLongAddress

static final long getLongAddress(java.lang.String address)
Converts the IP address in a number more suitable for comparison.
Validated with mapper.testRipe.
Parameters:
address - IP address.

whois

private static whoisHandler.CodeRange whois(java.lang.String address)
Version 1.0.4. Lock method. Returns the country code and the alloted range of addresses for a address.
Parameters:
address - requestor address.

search

private java.lang.String search(java.lang.String address)
Version 1.0.4. Search best PageBox based on the requestor address.
Parameters:
address - requestor address.

getDomain

public java.lang.String getDomain(java.lang.String host)
Service method. Extract domain part from host name.
Validated with mapper.testMisc.
Specified by:
getDomain in interface MapperIntf
Parameters:
host - host name.