refactor: Splits CandidateHarvester into an interface

and an abstract implementation.
This commit is contained in:
Boris Grozev 2016-09-08 12:09:34 -05:00
parent 94b3cb2661
commit 0abaef19e8
7 changed files with 61 additions and 20 deletions

View File

@ -0,0 +1,51 @@
/*
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed 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.ice4j.ice.harvest;
/**
* An abstract partial implementation of {@link CandidateHarvester}.
*
* @author Emil Ivov
* @author Lyubomir Marinov
* @author Boris Grozev
*/
public abstract class AbstractCandidateHarvester
implements CandidateHarvester
{
/**
* Manages statistics about harvesting time.
*/
private HarvestStatistics harvestStatistics = new HarvestStatistics();
/**
* {@inheritDoc}
*/
public HarvestStatistics getHarvestStatistics()
{
return harvestStatistics;
}
/**
* {@inheritDoc}
* @return
*/
public boolean isHostHarvester()
{
return false;
}
}

View File

@ -28,14 +28,10 @@ import org.ice4j.ice.*;
* *
* @author Emil Ivov * @author Emil Ivov
* @author Lyubomir Marinov * @author Lyubomir Marinov
* @author Boris Grozev
*/ */
public abstract class CandidateHarvester public interface CandidateHarvester
{ {
/**
* Manages statistics about harvesting time.
*/
private HarvestStatistics harvestStatistics = new HarvestStatistics();
/** /**
* Gathers all candidate addresses of the type that this * Gathers all candidate addresses of the type that this
* <tt>CandidateHarvester</tt> supports. The gathered candidate addresses * <tt>CandidateHarvester</tt> supports. The gathered candidate addresses
@ -52,7 +48,7 @@ public abstract class CandidateHarvester
* as they are discovered, they should also be returned in order to make * as they are discovered, they should also be returned in order to make
* sure that the gathering will be considered successful. * sure that the gathering will be considered successful.
*/ */
public abstract Collection<LocalCandidate> harvest(Component component); Collection<LocalCandidate> harvest(Component component);
/** /**
* Returns the statistics describing how well the various harvests of this * Returns the statistics describing how well the various harvests of this
@ -61,10 +57,7 @@ public abstract class CandidateHarvester
* @return The {@link HarvestStatistics} describing this harvester's * @return The {@link HarvestStatistics} describing this harvester's
* harvests. * harvests.
*/ */
public HarvestStatistics getHarvestStatistics() HarvestStatistics getHarvestStatistics();
{
return harvestStatistics;
}
/** /**
* Returns <tt>true</tt> if this <tt>CandidateHarvester</tt> is to be * Returns <tt>true</tt> if this <tt>CandidateHarvester</tt> is to be
@ -77,8 +70,5 @@ public abstract class CandidateHarvester
* @return <tt>true</tt> if this <tt>CandidateHarvester</tt> is a harvester * @return <tt>true</tt> if this <tt>CandidateHarvester</tt> is a harvester
* for host candidates. * for host candidates.
*/ */
public boolean isHostHarvester() boolean isHostHarvester();
{
return false;
}
} }

View File

@ -41,7 +41,7 @@ import java.util.*;
* @author Emil Ivov * @author Emil Ivov
*/ */
public class MappingCandidateHarvester public class MappingCandidateHarvester
extends CandidateHarvester extends AbstractCandidateHarvester
{ {
/** /**
* The addresses that we will use as a mask * The addresses that we will use as a mask

View File

@ -53,7 +53,7 @@ import java.util.logging.Logger; // Disambiguation
* @author Boris Grozev * @author Boris Grozev
*/ */
public class SinglePortUdpHarvester public class SinglePortUdpHarvester
extends CandidateHarvester extends AbstractCandidateHarvester
{ {
/** /**
* Our class logger. * Our class logger.

View File

@ -36,7 +36,7 @@ import org.ice4j.stack.*;
* @author Lyubomir Marinov * @author Lyubomir Marinov
*/ */
public class StunCandidateHarvester public class StunCandidateHarvester
extends CandidateHarvester extends AbstractCandidateHarvester
{ {
/** /**

View File

@ -46,7 +46,7 @@ import org.ice4j.socket.*;
* @author Lyubomir Marinov * @author Lyubomir Marinov
*/ */
public class TcpHarvester public class TcpHarvester
extends CandidateHarvester extends AbstractCandidateHarvester
{ {
/** /**
* Our class logger. * Our class logger.

View File

@ -34,7 +34,7 @@ import org.bitlet.weupnp.*;
* @author Sebastien Vincent * @author Sebastien Vincent
*/ */
public class UPNPHarvester public class UPNPHarvester
extends CandidateHarvester extends AbstractCandidateHarvester
{ {
/** /**
* The logger. * The logger.