-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andre Dietisheim <[email protected]>
- Loading branch information
Showing
30 changed files
with
776 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/redhat/devtools/intellij/telemetry/core/service/FeedbackEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.telemetry.core.service; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class FeedbackEvent extends Event { | ||
|
||
public FeedbackEvent(String name) { | ||
this(name, new HashMap<>()); | ||
} | ||
|
||
public FeedbackEvent(String name, Map<String, String> properties) { | ||
super(Type.ACTION, name, properties); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...main/java/com/redhat/devtools/intellij/telemetry/core/service/FeedbackMessageBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.telemetry.core.service; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.redhat.devtools.intellij.telemetry.core.IService; | ||
import com.redhat.devtools.intellij.telemetry.core.util.Lazy; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static com.redhat.devtools.intellij.telemetry.core.service.Event.Type.ACTION; | ||
|
||
public class FeedbackMessageBuilder { | ||
|
||
private static final Logger LOGGER = Logger.getInstance(FeedbackMessageBuilder.class); | ||
|
||
private final IService serviceFacade; | ||
|
||
public FeedbackMessageBuilder(ClassLoader classLoader) { | ||
this(new FeedbackServiceFacade(classLoader)); | ||
} | ||
|
||
FeedbackMessageBuilder(IService serviceFacade) { | ||
this.serviceFacade = serviceFacade; | ||
} | ||
|
||
static class FeedbackServiceFacade extends Lazy<IService> implements IService { | ||
|
||
protected FeedbackServiceFacade(final ClassLoader classLoader) { | ||
this(() -> ApplicationManager.getApplication().getService(FeedbackServiceFactory.class).create(classLoader)); | ||
} | ||
|
||
protected FeedbackServiceFacade(final Supplier<IService> supplier) { | ||
super(supplier); | ||
} | ||
|
||
@Override | ||
public void send(Event event) { | ||
get().send(event); | ||
} | ||
} | ||
|
||
public FeedbackMessage feedback(String name) { | ||
return new FeedbackMessage(name, serviceFacade); | ||
} | ||
|
||
public static class FeedbackMessage extends Message<FeedbackMessage>{ | ||
|
||
private FeedbackMessage(String name, IService service) { | ||
super(ACTION, name, service); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/redhat/devtools/intellij/telemetry/core/service/FeedbackService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.telemetry.core.service; | ||
|
||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.redhat.devtools.intellij.telemetry.core.IMessageBroker; | ||
import com.redhat.devtools.intellij.telemetry.core.IService; | ||
|
||
public class FeedbackService implements IService { | ||
|
||
private static final Logger LOGGER = Logger.getInstance(FeedbackService.class); | ||
|
||
protected final IMessageBroker broker; | ||
|
||
public FeedbackService(final IMessageBroker broker) { | ||
this.broker = broker; | ||
} | ||
|
||
@Override | ||
public void send(Event event) { | ||
broker.send(event); | ||
} | ||
|
||
public void dispose() { | ||
broker.dispose(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...main/java/com/redhat/devtools/intellij/telemetry/core/service/FeedbackServiceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.telemetry.core.service; | ||
|
||
import com.intellij.openapi.project.DumbAware; | ||
import com.redhat.devtools.intellij.telemetry.core.IMessageBroker; | ||
import com.redhat.devtools.intellij.telemetry.core.IService; | ||
import com.redhat.devtools.intellij.telemetry.core.configuration.TelemetryConfiguration; | ||
import com.redhat.devtools.intellij.telemetry.core.service.segment.SegmentBroker; | ||
import com.redhat.devtools.intellij.telemetry.core.service.segment.SegmentConfiguration; | ||
|
||
public class FeedbackServiceFactory implements DumbAware { | ||
|
||
public IService create(ClassLoader classLoader) { | ||
TelemetryConfiguration configuration = TelemetryConfiguration.getInstance(); | ||
IMessageBroker broker = createSegmentBroker(configuration.isDebug(), classLoader); | ||
return new FeedbackService(broker); | ||
} | ||
|
||
private IMessageBroker createSegmentBroker(boolean isDebug, ClassLoader classLoader) { | ||
SegmentConfiguration brokerConfiguration = new SegmentConfiguration(classLoader); | ||
return new SegmentBroker( | ||
isDebug, | ||
UserId.INSTANCE.get(), | ||
null, | ||
brokerConfiguration); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/com/redhat/devtools/intellij/telemetry/core/service/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.telemetry.core.service; | ||
|
||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.redhat.devtools.intellij.telemetry.core.IService; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
abstract class Message<T extends Message> { | ||
|
||
private static final Logger LOGGER = Logger.getInstance(Message.class); | ||
|
||
private final Event.Type type; | ||
private final Map<String, String> properties = new HashMap<>(); | ||
private final String name; | ||
private final IService service; | ||
|
||
protected Message(Event.Type type, String name, IService service) { | ||
this.name = name; | ||
this.type = type; | ||
this.service = service; | ||
} | ||
|
||
String getName() { | ||
return name; | ||
} | ||
|
||
Event.Type getType() { | ||
return type; | ||
} | ||
|
||
public T property(String key, String value) { | ||
if (key == null | ||
|| value == null) { | ||
LOGGER.warn("Ignored property with key: " + key + " value: " + value); | ||
} else { | ||
properties.put(key, value); | ||
} | ||
return (T) this; | ||
} | ||
|
||
String getProperty(String key) { | ||
return properties.get(key); | ||
} | ||
|
||
Map<String, String> properties() { | ||
return properties; | ||
} | ||
|
||
protected boolean hasProperty(String key) { | ||
return properties.containsKey(key); | ||
} | ||
|
||
public Event send() { | ||
Event event = new Event(type, name, new HashMap<>(properties)); | ||
service.send(event); | ||
return event; | ||
} | ||
} |
Oops, something went wrong.