| /** |
| * Copyright (c) 2015 Codetrails GmbH. |
| * 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 |
| */ |
| package aeri.rcp.silent; |
| |
| import static org.eclipse.epp.logging.aeri.core.util.LogListener.TOPIC_NEW_STATUS_LOGGED; |
| |
| import java.io.IOException; |
| |
| import javax.inject.Inject; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.NullProgressMonitor; |
| import org.eclipse.e4.core.contexts.IEclipseContext; |
| import org.eclipse.e4.core.di.annotations.Optional; |
| import org.eclipse.e4.core.di.extensions.EventTopic; |
| import org.eclipse.epp.logging.aeri.core.IModelFactory; |
| import org.eclipse.epp.logging.aeri.core.IProblemState; |
| import org.eclipse.epp.logging.aeri.core.ISendOptions; |
| import org.eclipse.epp.logging.aeri.core.IServerConnection; |
| import org.eclipse.jdt.annotation.NonNullByDefault; |
| |
| /** |
| * Simple single-server, no queue work-flow. Sends error status events silently to an (e.g, in-house) error reporting service. |
| */ |
| @SuppressWarnings("restriction") |
| @NonNullByDefault |
| public class InhouseReportingWorkflow { |
| |
| private IEclipseContext context; |
| private IServerConnection server; |
| |
| @Inject |
| public InhouseReportingWorkflow(IServerConnection server, IEclipseContext context) { |
| this.server = server; |
| this.context = context; |
| } |
| |
| @Inject |
| @Optional |
| void onNewStatusLogged(@EventTopic(TOPIC_NEW_STATUS_LOGGED) IStatus status) throws IOException { |
| ISendOptions options = IModelFactory.eINSTANCE.createSendOptions(); |
| IEclipseContext eventContext = context.createChild("Log event context"); |
| eventContext.set(IStatus.class, status); |
| eventContext.set(IServerConnection.class, server); |
| eventContext.set(ISendOptions.class, options); |
| |
| // Ask the server whether it is interested in this status. |
| // Most of the time, filtering should be done in an IStatus filter in the LogListener but there might be scenarios where accessing |
| // the server (now we are in the background thread) might be a better option. |
| IProblemState prediction = server.interested(status, eventContext, new NullProgressMonitor()); |
| switch (prediction.getStatus()) { |
| case FAILURE: |
| case IGNORED: |
| case INVALID: |
| return; |
| default: |
| } |
| |
| // send silently - no progress, no cancelation (demo purpose) |
| // You may use UploadReportsScheduler to upload reports using Eclipse Jobs API |
| server.submit(status, eventContext, new NullProgressMonitor()); |
| } |
| } |