com.netflix.hystrix.HystrixCommandMetrics Java Examples

The following examples show how to use com.netflix.hystrix.HystrixCommandMetrics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FwHystrixCommondCircuitClose.java    From fw-spring-cloud with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    ConfigurationManager.getConfigInstance().setProperty(
            "hystrix.command.default.circuitBreaker.requestVolumeThreshold", 3);
    boolean isTimeout = true;
    for (int i = 0; i < 10; i++) {
        MyCommand c = new MyCommand(isTimeout);
        c.execute();

        HystrixCommandMetrics.HealthCounts hc = c.getMetrics().getHealthCounts();
        System.out.println("健康数量:" + hc.getTotalRequests());
        if (c.isCircuitBreakerOpen()) {
            isTimeout = false;
            log.info("断路器打开了,第{}索引,等待休眠期结束",i);
            log.info("休眠6秒");
            Thread.sleep(6000);
        }
    }
}
 
Example #2
Source File: CircutBreakerEvent.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public CircutBreakerEvent(HystrixCommandKey commandKey, Type type) {
  super(type);
  HystrixCommandMetrics hystrixCommandMetrics = HystrixCommandMetrics.getInstance(commandKey);
  if (hystrixCommandMetrics != null) {
    if (hystrixCommandMetrics.getCommandGroup() instanceof CustomizeCommandGroupKey) {
      CustomizeCommandGroupKey customCommandGroupKey =
          (CustomizeCommandGroupKey) hystrixCommandMetrics.getCommandGroup();
      this.microservice = customCommandGroupKey.getInstance().getMicroserviceName();
      this.role = customCommandGroupKey.getInstance().getInvocationType().name();
      this.schema = customCommandGroupKey.getInstance().getSchemaId();
      this.operation = customCommandGroupKey.getInstance().getOperationName();
    }
    this.currentTotalRequest = hystrixCommandMetrics.getHealthCounts().getTotalRequests();
    this.currentErrorPercentage = hystrixCommandMetrics.getHealthCounts().getErrorCount();
    this.currentErrorCount = hystrixCommandMetrics.getHealthCounts().getErrorPercentage();
    this.requestVolumeThreshold = hystrixCommandMetrics.getProperties().circuitBreakerRequestVolumeThreshold().get();
    this.sleepWindowInMilliseconds =
        hystrixCommandMetrics.getProperties().circuitBreakerSleepWindowInMilliseconds().get();
    this.errorThresholdPercentage =
        hystrixCommandMetrics.getProperties().circuitBreakerErrorThresholdPercentage().get();
  }
}
 
Example #3
Source File: HystrixKafkaCircuitBreaker.java    From nakadi with MIT License 6 votes vote down vote up
public HystrixKafkaCircuitBreaker(final String brokerId) {
    commandKey = HystrixCommandKey.Factory.asKey(brokerId);
    commandProperties = HystrixPropertiesFactory.getCommandProperties(commandKey, null);
    threadPoolKey = HystrixThreadPoolKey.Factory.asKey(brokerId);
    hystrixCommandMetrics = HystrixCommandMetrics.getInstance(
            commandKey,
            HYSTRIX_CMD_GROUP_KEY,
            threadPoolKey,
            commandProperties);
    circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(
            commandKey,
            HYSTRIX_CMD_GROUP_KEY,
            commandProperties,
            hystrixCommandMetrics);
    concurrentExecutionCount = new AtomicInteger();
}
 
Example #4
Source File: CircuitBreakerCommand.java    From msf4j with Apache License 2.0 6 votes vote down vote up
private void printMetrics() {
    HystrixCommandMetrics metrics =
            HystrixCommandMetrics.
                    getInstance(HystrixCommandKey.Factory.asKey(this.getClass().getSimpleName()));
    StringBuilder m = new StringBuilder();
    if (metrics != null) {
        HystrixCommandMetrics.HealthCounts health = metrics.getHealthCounts();
        m.append("Requests: ").append(health.getTotalRequests()).append(" ");
        m.append("Errors: ").append(health.getErrorCount()).append(" (").
                append(health.getErrorPercentage()).append("%)   ");
        m.append("Mean: ").append(metrics.getExecutionTimePercentile(50)).append(" ");
        m.append("75th: ").append(metrics.getExecutionTimePercentile(75)).append(" ");
        m.append("90th: ").append(metrics.getExecutionTimePercentile(90)).append(" ");
        m.append("99th: ").append(metrics.getExecutionTimePercentile(99)).append(" ");
    }
    System.out.println(m);
}
 
Example #5
Source File: TenacityCircuitBreakerTest.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@Test
public void circuitBreakerShouldBeClosed() throws URISyntaxException, InterruptedException {
    final TenacityFailingCommand tenacityFailingCommand = new TenacityFailingCommand();
    tenacityFailingCommand
            .getCumulativeCommandEventCounterStream()
            .startCachingStreamValuesIfUnstarted();
    final int numberOfExecutions = 10;

    for (int i = 0; i < numberOfExecutions; i++) {
        new TenacityFailingCommand().execute();
        assertTrue("Allow request should be true", tenacityFailingCommand.getCircuitBreaker().allowRequest());
        assertFalse("Circuit Breaker should not be open", tenacityFailingCommand.isCircuitBreakerOpen());
    }

    Thread.sleep(1000);

    final HystrixCommandMetrics sleepCommandMetrics = tenacityFailingCommand.getCommandMetrics();
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS))
            .isEqualTo(10L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
            .isEqualTo(0L);
    assertTrue("Allow request should be true", tenacityFailingCommand.getCircuitBreaker().allowRequest());
    assertFalse("Circuit Breaker should not be open", tenacityFailingCommand.isCircuitBreakerOpen());
}
 
Example #6
Source File: TenacityCircuitBreakerTest.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@Test
public void circuitBreakerShouldOpen() throws URISyntaxException, InterruptedException {
    final TenacityFailingCommand tenacityFailingCommand = new TenacityFailingCommand();
    tenacityFailingCommand
            .getCumulativeCommandEventCounterStream()
            .startCachingStreamValuesIfUnstarted();
    final int numberOfExecutions = 500;

    for (int i = 0; i < numberOfExecutions; i++) {
        new TenacityFailingCommand().execute();

        //Allow for circuit breaker calculations to take place and open the circuit
        if (i == (numberOfExecutions / 2)) {
            Thread.sleep(500);
        }
    }

    Thread.sleep(1000);

    final HystrixCommandMetrics sleepCommandMetrics = tenacityFailingCommand.getCommandMetrics();
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isZero();
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS))
            .isEqualTo(numberOfExecutions);
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
            .isGreaterThan(50L);
    assertFalse("Allow request should be false", tenacityFailingCommand.getCircuitBreaker().allowRequest());
    assertTrue("Circuit Breaker should be open", tenacityFailingCommand.isCircuitBreakerOpen());
}
 
Example #7
Source File: HystrixMetricsStreamHandler.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
private Observable<Void> handleHystrixRequest(final HttpServerResponse<O> response) {
    writeHeaders(response);

    final Subject<Void, Void> subject = PublishSubject.create();
    final MultipleAssignmentSubscription subscription = new MultipleAssignmentSubscription();
    Subscription actionSubscription = Observable.timer(0, interval, TimeUnit.MILLISECONDS, Schedulers.computation())
            .subscribe(new Action1<Long>() {
                @Override
                public void call(Long tick) {
                    if (!response.getChannel().isOpen()) {
                        subscription.unsubscribe();
                        return;
                    }
                    try {
                        for (HystrixCommandMetrics commandMetrics : HystrixCommandMetrics.getInstances()) {
                            writeMetric(JsonMapper.toJson(commandMetrics), response);
                        }
                        for (HystrixThreadPoolMetrics threadPoolMetrics : HystrixThreadPoolMetrics.getInstances()) {
                            writeMetric(JsonMapper.toJson(threadPoolMetrics), response);
                        }
                    } catch (Exception e) {
                        subject.onError(e);
                    }
                }
            });
    subscription.set(actionSubscription);
    return subject;
}
 
Example #8
Source File: HystrixFaulttoleranceIntegrationTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private int getEventCountForCommand(HystrixRollingNumberEvent hystrixRollingNumberEvent, HystrixCommandKey commandKey) {
	HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(commandKey);
	if (metrics == null) {
		return 0;
	}
	int currentConcurrentExecutionCount = (int) metrics.getCumulativeCount(hystrixRollingNumberEvent);
	return currentConcurrentExecutionCount;
}
 
Example #9
Source File: HystrixFaulttoleranceIntegrationTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private void initMetrics(Ping ping) throws InterruptedException {
	// Black hystrix magic here :(
	try {
		ping.ping("foo");
	} catch (Exception e) {
	}
	HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
	HystrixCommandKey key = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
	
	HystrixCommandMetrics.getInstance(key).getCumulativeCount(HystrixEventType.SUCCESS);
}
 
Example #10
Source File: FaultToleranceMetricsTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private void initMetrics(Ping ping, AstrixContext context) {
	try {
		ping.ping("foo");
	} catch (Exception e) {
	}
	HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(context).getInstance(BeanFaultToleranceFactorySpi.class);
	HystrixCommandKey key = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
	HystrixCommandMetrics.getInstance(key).getCumulativeCount(HystrixEventType.SUCCESS);
}
 
Example #11
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private int getEventCountForCommand(HystrixRollingNumberEvent hystrixRollingNumberEvent) {
	HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
	HystrixCommandKey commandKey = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
	HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(commandKey);
	int currentConcurrentExecutionCount = (int) metrics.getCumulativeCount(hystrixRollingNumberEvent);
	return currentConcurrentExecutionCount;
}
 
Example #12
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private void initMetrics(Ping ping) throws InterruptedException {
	// Black hystrix magic here :(
	try {
		ping.ping();
	} catch (Exception e) {
	}
	HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
	HystrixCommandKey key = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
	
	HystrixCommandMetrics.getInstance(key).getCumulativeCount(HystrixEventType.SUCCESS);
}
 
Example #13
Source File: HystrixCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private int getEventCountForCommand(HystrixRollingNumberEvent hystrixRollingNumberEvent) {
	HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
	HystrixCommandKey commandKey = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
	HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(commandKey);
	int currentConcurrentExecutionCount = (int) metrics.getCumulativeCount(hystrixRollingNumberEvent);
	return currentConcurrentExecutionCount;
}
 
Example #14
Source File: HystrixCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private void initMetrics(Ping ping) throws InterruptedException {
	// Black hystrix magic here :(
	try {
		ping.ping("foo");
	} catch (Exception e) {
	}
	HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
	HystrixCommandKey key = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
	
	HystrixCommandMetrics.getInstance(key).getCumulativeCount(HystrixEventType.SUCCESS);
}
 
Example #15
Source File: TestCircutBreakerEventNotifier.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarkEvent() {
  Mockito.when(commandKey.name()).thenReturn("Consumer.springmvc.springmvcHello.sayHi");
  new Expectations(HystrixCommandMetrics.class) {
    {
      HystrixCommandMetrics.getInstance(commandKey);
      result = null;
    }
  };
  circutBreakerEventNotifier.markEvent(HystrixEventType.SHORT_CIRCUITED, commandKey);
  Assert.assertEquals(1, taskList.size());
  circutBreakerEventNotifier.markEvent(HystrixEventType.SUCCESS, commandKey);
  Assert.assertEquals(2, taskList.size());
}
 
Example #16
Source File: TenacityPropertiesTest.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Test
public void queueRejectionWithBlockingQueue() throws Exception {
    final int queueMaxSize = 5;
    final TenacityConfiguration exampleConfiguration = new TenacityConfiguration(
            new ThreadPoolConfiguration(1, 1, 10, queueMaxSize, 10000, 10),
            new CircuitBreakerConfiguration(20, 5000, 50, 10000, 10),
            new SemaphoreConfiguration(),
            5000,
            HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);

    final TenacityPropertyRegister tenacityPropertyRegister = new TenacityPropertyRegister(
            ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(DependencyKey.SLEEP, exampleConfiguration),
            new BreakerboxConfiguration(),
            mock(ArchaiusPropertyRegister.class));

    tenacityPropertyRegister.register();

    new SleepCommand(DependencyKey.SLEEP).getCumulativeCommandEventCounterStream().startCachingStreamValuesIfUnstarted();

    final ImmutableList.Builder<Future<Optional<String>>> sleepCommands = ImmutableList.builder();
    for (int i = 0; i < queueMaxSize * 2; i++) {
        sleepCommands.add(new SleepCommand(DependencyKey.SLEEP).queue());
    }

    checkFutures(sleepCommands.build());

    final HystrixCommandMetrics sleepCommandMetrics = new SleepCommand(DependencyKey.SLEEP).getCommandMetrics();
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED))
            .isEqualTo(4L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS))
            .isEqualTo(4L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
            .isEqualTo(0L);

    final HystrixThreadPoolProperties threadPoolProperties = new SleepCommand(DependencyKey.SLEEP).getThreadpoolProperties();

    final ThreadPoolConfiguration threadPoolConfiguration = exampleConfiguration.getThreadpool();
    assertEquals(threadPoolProperties.queueSizeRejectionThreshold().get().intValue(), threadPoolConfiguration.getQueueSizeRejectionThreshold());
    assertEquals(threadPoolProperties.maxQueueSize().get().intValue(), threadPoolConfiguration.getMaxQueueSize());

    assertEquals(TenacityPropertyStore.getTenacityConfiguration(DependencyKey.SLEEP), exampleConfiguration);
}
 
Example #17
Source File: TenacityPropertiesTest.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Test
public void queueRejectionWithSynchronousQueue() throws Exception {
    new SleepCommand(DependencyKey.EXAMPLE)
            .getCumulativeCommandEventCounterStream()
            .startCachingStreamValuesIfUnstarted();

    final ImmutableCollection.Builder<Future<Optional<String>>> futures = ImmutableList.builder();
    for (int i = 0; i < 50; i++) {
        futures.add(new SleepCommand(DependencyKey.EXAMPLE).queue());
    }

    checkFutures(futures.build());

    Thread.sleep(500);

    final HystrixCommandMetrics sleepCommandMetrics = new SleepCommand(DependencyKey.EXAMPLE).getCommandMetrics();
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED))
            .isGreaterThan(15L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS))
            .isGreaterThanOrEqualTo(40L);
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_FAILURE))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_REJECTION))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
            .isEqualTo(sleepCommandMetrics.getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS) -
                    sleepCommandMetrics.getCumulativeCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED));

    final HystrixThreadPoolProperties threadPoolProperties = new SleepCommand(DependencyKey.EXAMPLE).getThreadpoolProperties();

    //-1 means no limit on the number of items in the queue, which uses the SynchronousBlockingQueue
    assertEquals(threadPoolProperties.maxQueueSize().get().intValue(), -1);
    assertEquals(TenacityPropertyStore.getTenacityConfiguration(DependencyKey.EXAMPLE),
            new TenacityConfiguration(new ThreadPoolConfiguration(), new CircuitBreakerConfiguration(),
                    new SemaphoreConfiguration(), 1000, HystrixCommandProperties.ExecutionIsolationStrategy.THREAD));
}
 
Example #18
Source File: HystrixMetricsProcessingJob.java    From cerberus with Apache License 2.0 4 votes vote down vote up
public void processHystrixCommandMetrics() {
  for (HystrixCommandMetrics metrics : HystrixCommandMetrics.getInstances()) {
    Map<String, String> dimensions =
        ImmutableMap.of(
            "key", metrics.getCommandKey().name(),
            "group", metrics.getCommandGroup().name());
    boolean isCircuitOpen =
        HystrixCircuitBreaker.Factory.getInstance(metrics.getCommandKey()).isOpen();

    log.debug(
        "group:{}, commandKey:{}, CircuitOpen:{}, Mean:{}, 95%:{}, 99%:{}, 99.5%:{}, {}",
        metrics.getCommandGroup().name(),
        metrics.getCommandKey().name(),
        isCircuitOpen,
        metrics.getExecutionTimeMean(),
        metrics.getExecutionTimePercentile(95.0),
        metrics.getExecutionTimePercentile(99.0),
        metrics.getExecutionTimePercentile(99.5),
        metrics.getHealthCounts());

    metricsService.getOrCreateCallbackGauge(
        "hystrix.command.circuit_open", () -> isCircuitOpen ? 1 : 0, dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.command.exec_time.mean", metrics::getExecutionTimeMean, dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.command.exec_time.95th",
        () -> metrics.getExecutionTimePercentile(95.0),
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.command.exec_time.99th",
        () -> metrics.getExecutionTimePercentile(99.0),
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.command.rolling.max_concurrent_execs",
        metrics::getRollingMaxConcurrentExecutions,
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.command.total_count",
        () -> metrics.getHealthCounts().getTotalRequests(),
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.command.error_count",
        () -> metrics.getHealthCounts().getErrorCount(),
        dimensions);
  }
}
 
Example #19
Source File: HystrixServlet.java    From s2g-zuul with MIT License 4 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	PrintWriter writer = resp.getWriter();
	try {

		// make a writable copy of the immutable System.getenv() map
		Map<String, String> breakerMap = new TreeMap<String, String>();

		for (HystrixCommandMetrics commandMetrics : HystrixCommandMetrics.getInstances()) {
			HystrixCommandKey key = commandMetrics.getCommandKey();
			HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);

			if (circuitBreaker != null) {
				if (circuitBreaker.isOpen()) {
					breakerMap.put(key.name(), DynamicPropertyFactory.getInstance().getStringProperty("mail."+key.name(), "[email protected]").get());
				}else{
					if(DynamicPropertyFactory.getInstance().getBooleanProperty("hystrix.command."+key.name()+".circuitBreaker.forceOpen",false).get()){
						breakerMap.put(key.name(), DynamicPropertyFactory.getInstance().getStringProperty("mail."+key.name(), "[email protected]").get());
					}else if(DynamicPropertyFactory.getInstance().getBooleanProperty("hystrix.command.default.circuitBreaker.forceOpen",false).get()){
						breakerMap.put(key.name(), DynamicPropertyFactory.getInstance().getStringProperty("mail."+key.name(), "[email protected]").get());							
					}
				}
			}
		}

		String jsonStr = JSON.toJSONString(breakerMap);

		resp.addHeader("Access-Control-Allow-Origin", "*");
		resp.addHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
		resp.setContentType("application/json; charset=UTF-8");

		writer.write(jsonStr);
		resp.setStatus(Response.SC_OK);
	}catch(Throwable t){
		writer.write(t.getMessage());
		resp.setStatus(Response.SC_INTERNAL_SERVER_ERROR);
	}finally {
	
		if (writer != null) {
			writer.close();
		}
	}
}