Skip to content

Commit 5041b59

Browse files
committed
Merge branch 'master' into spi
2 parents d748cb5 + 1870d7d commit 5041b59

40 files changed

Lines changed: 2090 additions & 55 deletions

File tree

agents/ls-yaml/pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2012-2017 Red Hat, Inc.
5+
All rights reserved. This program and the accompanying materials
6+
are made available under the terms of the Eclipse Public License v1.0
7+
which accompanies this distribution, and is available at
8+
http://www.eclipse.org/legal/epl-v10.html
9+
10+
Contributors:
11+
Red Hat, Inc. - initial API and implementation
12+
13+
-->
14+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
15+
<modelVersion>4.0.0</modelVersion>
16+
<parent>
17+
<artifactId>che-agents-parent</artifactId>
18+
<groupId>org.eclipse.che</groupId>
19+
<version>5.19.0-SNAPSHOT</version>
20+
</parent>
21+
<artifactId>ls-yaml-agent</artifactId>
22+
<name>Language Server Yaml Agent</name>
23+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "org.eclipse.che.ls.yaml",
3+
"version": "1.0.0",
4+
"name": "Yaml language server",
5+
"description": "Yaml intellisense",
6+
"dependencies": [],
7+
"properties": {}
8+
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#
2+
# Copyright (c) 2012-2017 Red Hat, Inc.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License v1.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-v10.html
7+
#
8+
# Contributors:
9+
# Red Hat, Inc. - initial API and implementation
10+
#
11+
12+
is_current_user_root() {
13+
test "$(id -u)" = 0
14+
}
15+
16+
is_current_user_sudoer() {
17+
sudo -n true > /dev/null 2>&1
18+
}
19+
20+
set_sudo_command() {
21+
if is_current_user_sudoer && ! is_current_user_root; then SUDO="sudo -E"; else unset SUDO; fi
22+
}
23+
24+
set_sudo_command
25+
unset PACKAGES
26+
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
27+
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
28+
29+
AGENT_BINARIES_URI=http://download.jboss.org/jbosstools/oxygen/stable/builds/yaml-language-server/yaml-language-server-latest.tar.gz
30+
CHE_DIR=$HOME/che
31+
LS_DIR=${CHE_DIR}/ls-yaml
32+
LS_LAUNCHER=${LS_DIR}/launch.sh
33+
34+
if [ -f /etc/centos-release ]; then
35+
FILE="/etc/centos-release"
36+
LINUX_TYPE=$(cat $FILE | awk '{print $1}')
37+
elif [ -f /etc/redhat-release ]; then
38+
FILE="/etc/redhat-release"
39+
LINUX_TYPE=$(cat $FILE | cut -c 1-8)
40+
else
41+
FILE="/etc/os-release"
42+
LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')
43+
LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)
44+
fi
45+
46+
MACHINE_TYPE=$(uname -m)
47+
48+
mkdir -p ${CHE_DIR}
49+
mkdir -p ${LS_DIR}
50+
51+
########################
52+
### Install packages ###
53+
########################
54+
55+
# Red Hat Enterprise Linux 7
56+
############################
57+
if echo ${LINUX_TYPE} | grep -qi "rhel"; then
58+
test "${PACKAGES}" = "" || {
59+
${SUDO} yum install ${PACKAGES};
60+
}
61+
62+
command -v nodejs >/dev/null 2>&1 || {
63+
curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;
64+
${SUDO} yum -y install nodejs;
65+
}
66+
67+
# Red Hat Enterprise Linux 6
68+
############################
69+
elif echo ${LINUX_TYPE} | grep -qi "Red Hat"; then
70+
test "${PACKAGES}" = "" || {
71+
${SUDO} yum install ${PACKAGES};
72+
}
73+
74+
command -v nodejs >/dev/null 2>&1 || {
75+
curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;
76+
${SUDO} yum -y install nodejs;
77+
}
78+
79+
80+
# Ubuntu 14.04 16.04 / Linux Mint 17
81+
####################################
82+
elif echo ${LINUX_TYPE} | grep -qi "ubuntu"; then
83+
test "${PACKAGES}" = "" || {
84+
${SUDO} apt-get update;
85+
${SUDO} apt-get -y install ${PACKAGES};
86+
}
87+
88+
command -v nodejs >/dev/null 2>&1 || {
89+
{
90+
curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} bash -;
91+
};
92+
93+
${SUDO} apt-get update;
94+
${SUDO} apt-get install -y nodejs;
95+
}
96+
97+
98+
# Debian 8
99+
##########
100+
elif echo ${LINUX_TYPE} | grep -qi "debian"; then
101+
test "${PACKAGES}" = "" || {
102+
${SUDO} apt-get update;
103+
${SUDO} apt-get -y install ${PACKAGES};
104+
}
105+
106+
command -v nodejs >/dev/null 2>&1 || {
107+
{
108+
curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} bash -;
109+
};
110+
111+
${SUDO} apt-get update;
112+
${SUDO} apt-get install -y nodejs;
113+
}
114+
115+
# Fedora 23
116+
###########
117+
elif echo ${LINUX_TYPE} | grep -qi "fedora"; then
118+
command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" procps-ng"; }
119+
test "${PACKAGES}" = "" || {
120+
${SUDO} dnf -y install ${PACKAGES};
121+
}
122+
123+
command -v nodejs >/dev/null 2>&1 || {
124+
curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;
125+
${SUDO} dnf -y install nodejs;
126+
}
127+
128+
129+
# CentOS 7.1 & Oracle Linux 7.1
130+
###############################
131+
elif echo ${LINUX_TYPE} | grep -qi "centos"; then
132+
test "${PACKAGES}" = "" || {
133+
${SUDO} yum -y install ${PACKAGES};
134+
}
135+
136+
command -v nodejs >/dev/null 2>&1 || {
137+
curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;
138+
${SUDO} yum -y install nodejs;
139+
}
140+
141+
# openSUSE 13.2
142+
###############
143+
elif echo ${LINUX_TYPE} | grep -qi "opensuse"; then
144+
test "${PACKAGES}" = "" || {
145+
${SUDO} zypper install -y ${PACKAGES};
146+
}
147+
148+
command -v nodejs >/dev/null 2>&1 || {
149+
${SUDO} zypper ar http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_13.1/ Node.js
150+
${SUDO} zypper in nodejs
151+
}
152+
153+
else
154+
>&2 echo "Unrecognized Linux Type"
155+
>&2 cat $FILE
156+
exit 1
157+
fi
158+
159+
160+
########################
161+
### Install Yaml LS ###
162+
########################
163+
164+
curl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${LS_DIR}
165+
166+
touch ${LS_LAUNCHER}
167+
chmod +x ${LS_LAUNCHER}
168+
echo "nodejs ${LS_DIR}/out/server/src/server.js --stdio" > ${LS_LAUNCHER}

agents/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@
3737
<module>ls-typescript</module>
3838
<module>ls-csharp</module>
3939
<module>test-ls</module>
40+
<module>ls-yaml</module>
4041
</modules>
4142
</project>

assembly/assembly-ide-war/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@
211211
<groupId>org.eclipse.che.plugin</groupId>
212212
<artifactId>che-plugin-web-ext-web</artifactId>
213213
</dependency>
214+
<dependency>
215+
<groupId>org.eclipse.che.plugin</groupId>
216+
<artifactId>che-plugin-yaml-ide</artifactId>
217+
</dependency>
218+
<dependency>
219+
<groupId>org.eclipse.che.plugin</groupId>
220+
<artifactId>che-plugin-yaml-shared</artifactId>
221+
</dependency>
214222
<dependency>
215223
<groupId>org.eclipse.che.plugin</groupId>
216224
<artifactId>che-plugin-zend-debugger-ide</artifactId>

assembly/assembly-wsagent-war/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@
139139
<groupId>org.eclipse.che.plugin</groupId>
140140
<artifactId>che-plugin-web-ext-server</artifactId>
141141
</dependency>
142+
<dependency>
143+
<groupId>org.eclipse.che.plugin</groupId>
144+
<artifactId>che-plugin-yaml-server</artifactId>
145+
</dependency>
146+
<dependency>
147+
<groupId>org.eclipse.che.plugin</groupId>
148+
<artifactId>che-plugin-yaml-shared</artifactId>
149+
</dependency>
142150
<dependency>
143151
<groupId>org.eclipse.che.plugin</groupId>
144152
<artifactId>che-plugin-zend-debugger-server</artifactId>

assembly/assembly-wsmaster-war/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
<groupId>org.eclipse.che</groupId>
105105
<artifactId>ls-typescript-agent</artifactId>
106106
</dependency>
107+
<dependency>
108+
<groupId>org.eclipse.che</groupId>
109+
<artifactId>ls-yaml-agent</artifactId>
110+
</dependency>
107111
<dependency>
108112
<groupId>org.eclipse.che</groupId>
109113
<artifactId>ssh-agent</artifactId>

core/che-core-api-core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
<groupId>org.eclipse.che.core</groupId>
8787
<artifactId>che-core-commons-lang</artifactId>
8888
</dependency>
89+
<dependency>
90+
<groupId>org.eclipse.che.core</groupId>
91+
<artifactId>che-core-commons-schedule</artifactId>
92+
</dependency>
8993
<dependency>
9094
<groupId>org.everrest</groupId>
9195
<artifactId>everrest-core</artifactId>

core/che-core-api-core/src/main/java/org/eclipse/che/api/core/websocket/impl/MessagesReSender.java

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111
package org.eclipse.che.api.core.websocket.impl;
1212

13-
import java.util.ArrayList;
14-
import java.util.HashMap;
15-
import java.util.LinkedList;
16-
import java.util.List;
13+
import com.google.common.collect.EvictingQueue;
1714
import java.util.Map;
1815
import java.util.Optional;
16+
import java.util.Queue;
17+
import java.util.concurrent.ConcurrentHashMap;
1918
import javax.inject.Inject;
2019
import javax.inject.Singleton;
2120
import javax.websocket.Session;
21+
import org.eclipse.che.commons.schedule.ScheduleDelay;
2222

2323
/**
2424
* Instance is responsible for re-sending messages that were not sent during the period when WEB
@@ -29,57 +29,77 @@
2929
*/
3030
@Singleton
3131
public class MessagesReSender {
32+
3233
private static final int MAX_MESSAGES = 100;
3334

3435
private final WebSocketSessionRegistry registry;
3536

36-
private final Map<String, List<String>> messagesMap = new HashMap<>();
37+
private final Map<String, Queue<DelayedMessage>> delayedMessageRegistry =
38+
new ConcurrentHashMap<>();
3739

3840
@Inject
3941
public MessagesReSender(WebSocketSessionRegistry registry) {
4042
this.registry = registry;
4143
}
4244

43-
public void add(String endpointId, String message) {
44-
List<String> messages = messagesMap.get(endpointId);
45+
@ScheduleDelay(initialDelay = 60, delay = 60)
46+
void cleanStaleMessages() {
47+
long currentTimeMillis = System.currentTimeMillis();
4548

46-
if (messages == null) {
47-
messages = new LinkedList<>();
48-
messagesMap.put(endpointId, messages);
49-
}
49+
delayedMessageRegistry
50+
.values()
51+
.forEach(it -> it.removeIf(m -> currentTimeMillis - m.timeMillis > 60_000));
5052

51-
if (messages.size() <= MAX_MESSAGES) {
52-
messages.add(message);
53-
}
53+
delayedMessageRegistry.values().removeIf(Queue::isEmpty);
54+
}
55+
56+
public void add(String endpointId, String message) {
57+
58+
delayedMessageRegistry
59+
.computeIfAbsent(endpointId, k -> EvictingQueue.create(MAX_MESSAGES))
60+
.offer(new DelayedMessage(message));
5461
}
5562

5663
public void resend(String endpointId) {
57-
final List<String> messages = messagesMap.remove(endpointId);
64+
Queue<DelayedMessage> delayedMessages = delayedMessageRegistry.remove(endpointId);
5865

59-
if (messages == null || messages.isEmpty()) {
66+
if (delayedMessages == null || delayedMessages.isEmpty()) {
6067
return;
6168
}
6269

63-
final Optional<Session> sessionOptional = registry.get(endpointId);
70+
Optional<Session> sessionOptional = registry.get(endpointId);
6471

6572
if (!sessionOptional.isPresent()) {
6673
return;
6774
}
6875

69-
final Session session = sessionOptional.get();
70-
71-
final List<String> backing = new ArrayList<>(messages);
72-
messages.clear();
73-
74-
for (String message : backing) {
76+
Queue<DelayedMessage> backingQueue = EvictingQueue.create(delayedMessages.size());
77+
while (!delayedMessages.isEmpty()) {
78+
backingQueue.offer(delayedMessages.poll());
79+
}
7580

81+
Session session = sessionOptional.get();
82+
for (DelayedMessage delayedMessage : backingQueue) {
7683
if (session.isOpen()) {
77-
session.getAsyncRemote().sendText(message);
84+
session.getAsyncRemote().sendText(delayedMessage.message);
7885
} else {
79-
messages.add(message);
86+
delayedMessages.add(delayedMessage);
8087
}
8188
}
8289

83-
messagesMap.put(endpointId, messages);
90+
if (!delayedMessages.isEmpty()) {
91+
delayedMessageRegistry.put(endpointId, delayedMessages);
92+
}
93+
}
94+
95+
private static class DelayedMessage {
96+
97+
private final long timeMillis;
98+
private final String message;
99+
100+
private DelayedMessage(String message) {
101+
this.message = message;
102+
this.timeMillis = System.currentTimeMillis();
103+
}
84104
}
85105
}

0 commit comments

Comments
 (0)