class InstanceRegistry extends PeerAwareInstanceRegistryImpl implements ApplicationContextAware {

	private static final Log log = LogFactory.getLog(InstanceRegistry.class);

	private ApplicationContext ctxt;

	private final int defaultOpenForTrafficCount;

	public InstanceRegistry(EurekaServerConfig serverConfig, EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
			EurekaClient eurekaClient, EurekaServerHttpClientFactory eurekaServerHttpClientFactory,
			int expectedNumberOfClientsSendingRenews, int defaultOpenForTrafficCount) {
		super(serverConfig, clientConfig, serverCodecs, eurekaClient, eurekaServerHttpClientFactory);

		this.expectedNumberOfClientsSendingRenews = expectedNumberOfClientsSendingRenews;
		this.defaultOpenForTrafficCount = defaultOpenForTrafficCount;
	}

	@Override
	public void setApplicationContext(ApplicationContext context) throws BeansException {
		this.ctxt = context;
	}

	/**
	 * If
	 * {@link PeerAwareInstanceRegistryImpl#openForTraffic(ApplicationInfoManager, int)}
	 * is called with a zero argument, it means that leases are not automatically
	 * cancelled if the instance hasn't sent any renewals recently. This happens for a
	 * standalone server. It seems like a bad default, so we set it to the smallest
	 * non-zero value we can, so that any instances that subsequently register can bump up
	 * the threshold.
	 */
	@Override
	public void openForTraffic(ApplicationInfoManager applicationInfoManager, int count) {
		super.openForTraffic(applicationInfoManager, count == 0 ? this.defaultOpenForTrafficCount : count);
	}

	@Override
	public void register(InstanceInfo info, int leaseDuration, boolean isReplication) {
		super.register(info, leaseDuration, isReplication);
		handleRegistration(info, leaseDuration, isReplication);
	}

	@Override
	public void register(final InstanceInfo info, final boolean isReplication) {
		super.register(info, isReplication);
		handleRegistration(info, resolveInstanceLeaseDuration(info), isReplication);
	}

	@Override
	public boolean cancel(String appName, String serverId, boolean isReplication) {
		final boolean cancelled = super.cancel(appName, serverId, isReplication);
		if (cancelled) {
			handleCancelation(appName, serverId, isReplication);
		}
		return cancelled;
	}

	@Override
	public boolean renew(final String appName, final String serverId, boolean isReplication) {
		final boolean renewed = super.renew(appName, serverId, isReplication);
		if (renewed) {
			handleRenewal(appName, serverId, isReplication);
		}
		return renewed;
	}

	@Override
	protected boolean internalCancel(String appName, String id, boolean isReplication) {
		final boolean cancelled = super.internalCancel(appName, id, isReplication);
		if (cancelled) {
			handleCancelation(appName, id, isReplication);
		}
		return cancelled;
	}

	private void handleCancelation(String appName, String id, boolean isReplication) {
		log("cancelled " + appName + ", serverId " + id + ", isReplication " + isReplication);
		publishEvent(new EurekaInstanceCanceledEvent(this, appName, id, isReplication));
	}

	private void handleRegistration(InstanceInfo info, int leaseDuration, boolean isReplication) {
		log("registered " + info.getAppName() + ", vip " + info.getVIPAddress() + ", leaseDuration " + leaseDuration
				+ ", isReplication " + isReplication);
		publishEvent(new EurekaInstanceRegisteredEvent(this, info, leaseDuration, isReplication));
	}

	private void handleRenewal(final String appName, final String serverId, boolean isReplication) {<FILL_FUNCTION_BODY>}

	private void log(String message) {
		if (log.isDebugEnabled()) {
			log.debug(message);
		}
	}

	private void publishEvent(ApplicationEvent applicationEvent) {
		this.ctxt.publishEvent(applicationEvent);
	}

	private int resolveInstanceLeaseDuration(final InstanceInfo info) {
		int leaseDuration = Lease.DEFAULT_DURATION_IN_SECS;
		if (info.getLeaseInfo() != null && info.getLeaseInfo().getDurationInSecs() > 0) {
			leaseDuration = info.getLeaseInfo().getDurationInSecs();
		}
		return leaseDuration;
	}

}

		log("renewed " + appName + ", serverId " + serverId + ", isReplication " + isReplication);
		final Application application = getApplication(appName);
		if (application != null) {
			final InstanceInfo instanceInfo = application.getByInstanceId(serverId);
			if (instanceInfo != null) {
				publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, instanceInfo, isReplication));
			}
		}
	
<methods>public void <init>(com.netflix.eureka.EurekaServerConfig, com.netflix.discovery.EurekaClientConfig, com.netflix.eureka.resources.ServerCodecs, com.netflix.discovery.EurekaClient, com.netflix.eureka.transport.EurekaServerHttpClientFactory) ,public boolean cancel(java.lang.String, java.lang.String, boolean) ,public boolean deleteStatusOverride(java.lang.String, java.lang.String, com.netflix.appinfo.InstanceInfo.InstanceStatus, java.lang.String, boolean) ,public long getLocalRegistrySize() ,public com.netflix.appinfo.InstanceInfo getNextServerFromEureka(java.lang.String, boolean) ,public long getNumOfReplicationsInLastMin() ,public List<com.netflix.eureka.cluster.PeerEurekaNode> getReplicaNodes() ,public List<com.netflix.discovery.shared.Application> getSortedApplications() ,public void init(com.netflix.eureka.cluster.PeerEurekaNodes) throws java.lang.Exception,public int isBelowRenewThresold() ,public boolean isLeaseExpirationEnabled() ,public int isLeaseExpirationEnabledMetric() ,public boolean isRegisterable(com.netflix.appinfo.InstanceInfo) ,public boolean isSelfPreservationModeEnabled() ,public int isSelfPreservationModeEnabledMetric() ,public void openForTraffic(com.netflix.appinfo.ApplicationInfoManager, int) ,public void register(com.netflix.appinfo.InstanceInfo, boolean) ,public boolean renew(java.lang.String, java.lang.String, boolean) ,public boolean shouldAllowAccess() ,public boolean shouldAllowAccess(boolean) ,public int shouldAllowAccessMetric() ,public void shutdown() ,public void statusUpdate(java.lang.String, com.netflix.eureka.resources.ASGResource.ASGStatus, boolean) ,public boolean statusUpdate(java.lang.String, java.lang.String, com.netflix.appinfo.InstanceInfo.InstanceStatus, java.lang.String, boolean) ,public int syncUp() <variables>private static final Comparator<com.netflix.discovery.shared.Application> APP_COMPARATOR,private static final int PRIME_PEER_NODES_RETRY_MS,private static final java.lang.String US_EAST_1,protected final com.netflix.discovery.EurekaClient eurekaClient,private final com.netflix.eureka.registry.rule.InstanceStatusOverrideRule instanceStatusOverrideRule,private static final org.slf4j.Logger logger,private final com.netflix.eureka.util.MeasuredRate numberOfReplicationsLastMin,protected volatile com.netflix.eureka.cluster.PeerEurekaNodes peerEurekaNodes,private boolean peerInstancesTransferEmptyOnStartup,private long startupTime,private java.util.Timer timer