Skip to content

Commit

Permalink
Adds system graceful stop tracking events
Browse files Browse the repository at this point in the history
3 new events are added, they are:

* STOPPING_SERVICE - published before service is stopped
* SERVICE_ITEM_STOPPED - published each time service item(like workspace) is stopped
* SERVICE_STOPPED - published after service is stopped
  • Loading branch information
Yevhenii Voevodin committed Feb 7, 2017
1 parent ee95f2c commit f2bcdfb
Show file tree
Hide file tree
Showing 22 changed files with 982 additions and 37 deletions.
4 changes: 4 additions & 0 deletions wsmaster/che-core-api-system-shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-dto</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.system.shared.dto;

import org.eclipse.che.dto.shared.DTO;

/**
* DTO for system service events.
*
* @author Yevhenii Voevodin
*/
@DTO
public interface SystemServiceEventDto extends SystemEventDto {

/**
* Returns the name of the service described by this event.
*/
String getService();

void setService(String service);

SystemServiceEventDto withService(String service);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.system.shared.dto;

import org.eclipse.che.api.system.shared.event.EventType;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.dto.shared.DTO;

/**
* See {@link EventType#SERVICE_ITEM_STOPPED} for details.
*
* @author Yevhenii Voevodin
*/
@DTO
public interface SystemServiceItemStoppedEventDto extends SystemServiceEventDto {

/**
* Returns an item for which this event is published(like workspace id).
*/
String getItem();

void setItem(String item);

SystemServiceItemStoppedEventDto withItem(String item);

/**
* Returns an amount of items currently stopped, it's either present
* with {@link #getTotal()} or missing at all(null is returned).
*/
@Nullable
Integer getCurrent();

void setCurrent(Integer current);

SystemServiceItemStoppedEventDto withCurrent(Integer current);

/**
* Returns total count of items which had not been stopped before
* service shutdown was called. It's either present with {@link #getCurrent()}
* or missing at all(null is returned).
*/
@Nullable
Integer getTotal();

void setTotal(Integer total);

SystemServiceItemStoppedEventDto withTotal(Integer total);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,28 @@ public enum EventType {
/**
* Published when system status is changed.
*/
STATUS_CHANGED
STATUS_CHANGED,

/**
* Published when system is starting shutting down a service.
* This is the first event published for a certain service.
*
* <pre>
* STOPPING_SERVICE -> (0..N)SERVICE_ITEM_STOPPED -> SERVICE_STOPPED
* </pre>
*/
STOPPING_SERVICE,

/**
* Published after service item is stopped.
* Events of such type are published between {@link #STOPPING_SERVICE}
* and {@link #SERVICE_STOPPED} events.
*/
SERVICE_ITEM_STOPPED,

/**
* Published when shutting down of a service is finished.
* The last event in the chain for a certain service.
*/
SERVICE_STOPPED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.system.shared.event.service;

import org.eclipse.che.api.system.shared.event.EventType;

/**
* See {@link EventType#STOPPING_SERVICE} description.
*
* @author Yevhenii Voevodin
*/
public class StoppingSystemServiceEvent extends SystemServiceEvent {

public StoppingSystemServiceEvent(String serviceName) {
super(serviceName);
}

@Override
public EventType getType() {
return EventType.STOPPING_SERVICE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.system.shared.event.service;

import org.eclipse.che.api.system.shared.event.SystemEvent;

import java.util.Objects;

/**
* The base class for system service events.
*
* @author Yevhenii Voevodin
*/
public abstract class SystemServiceEvent implements SystemEvent {

protected final String serviceName;

protected SystemServiceEvent(String serviceName) {
this.serviceName = Objects.requireNonNull(serviceName, "Service name required");
}

public String getServiceName() {
return serviceName;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof SystemServiceEvent)) {
return false;
}
final SystemServiceEvent that = (SystemServiceEvent)obj;
return Objects.equals(getType(), that.getType())
&& Objects.equals(serviceName, that.serviceName);
}

@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Objects.hashCode(getType());
hash = 31 * hash + Objects.hashCode(serviceName);
return hash;
}

@Override
public String toString() {
return getClass().getSimpleName() + "{eventType='" + getType() + "', serviceName=" + serviceName + "'}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.system.shared.event.service;

import org.eclipse.che.api.system.shared.event.EventType;
import org.eclipse.che.commons.annotation.Nullable;

import java.util.Objects;

/**
* See {@link EventType#SERVICE_ITEM_STOPPED} description.
*
* @author Yevhenii Voevodin
*/
public class SystemServiceItemStoppedEvent extends SystemServiceEvent {

private final String item;

private Integer total;
private Integer current;

public SystemServiceItemStoppedEvent(String serviceName, String item) {
super(serviceName);
this.item = Objects.requireNonNull(item, "Item required");
}

public SystemServiceItemStoppedEvent(String serviceName,
String item,
@Nullable Integer current,
@Nullable Integer total) {
this(serviceName, item);
this.current = current;
this.total = total;
}

@Override
public EventType getType() {
return EventType.SERVICE_ITEM_STOPPED;
}

public String getItem() {
return item;
}

@Nullable
public Integer getTotal() {
return total;
}

@Nullable
public Integer getCurrent() {
return current;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof SystemServiceItemStoppedEvent)) {
return false;
}
final SystemServiceItemStoppedEvent that = (SystemServiceItemStoppedEvent)obj;
return super.equals(that)
&& item.equals(that.item)
&& Objects.equals(total, that.total)
&& Objects.equals(current, that.current);
}

@Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + super.hashCode();
hash = 31 * hash + item.hashCode();
hash = 31 * hash + Objects.hashCode(total);
hash = 31 * hash + Objects.hashCode(current);
return hash;
}

@Override
public String toString() {
return "SystemServiceItemStoppedEvent{" +
"item='" + item + '\'' +
", total=" + total +
", current=" + current +
", eventType='" + getType() + '\'' +
", service='" + getServiceName() +
"\'}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.system.shared.event.service;

import org.eclipse.che.api.system.shared.event.EventType;

/**
* See {@link EventType#SERVICE_STOPPED} description.
*
* @author Yevhenii Voevodin
*/
public class SystemServiceStoppedEvent extends SystemServiceEvent {

public SystemServiceStoppedEvent(String serviceName) {
super(serviceName);
}

@Override
public EventType getType() {
return EventType.SERVICE_STOPPED;
}
}
14 changes: 11 additions & 3 deletions wsmaster/che-core-api-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-dto</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-model</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-system-shared</artifactId>
Expand All @@ -68,11 +72,15 @@
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-lang</artifactId>
<artifactId>che-core-api-workspace-shared</artifactId>
</dependency>
<dependency>
<groupId>org.everrest</groupId>
<artifactId>everrest-websockets</artifactId>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Loading

0 comments on commit f2bcdfb

Please sign in to comment.