Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.onloupe.agent;
import java.awt.DisplayMode;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.onloupe.configuration.AgentConfiguration;
import com.onloupe.configuration.PublisherConfiguration;
import com.onloupe.core.data.PathManager;
import com.onloupe.core.data.PathType;
import com.onloupe.core.monitor.LocalRepository;
import com.onloupe.core.serialization.monitor.LogMessagePacket;
import com.onloupe.core.serialization.monitor.SessionSummaryPacket;
import com.onloupe.core.util.SystemUtils;
import com.onloupe.core.util.TypeUtils;
import com.onloupe.model.data.ProcessorArchitecture;
import com.onloupe.model.session.ISessionSummary;
import com.onloupe.model.session.SessionStatus;
import com.onloupe.model.system.ApplicationType;
import com.onloupe.model.system.OSBootMode;
import com.onloupe.model.system.Version;
/**
* Summary information about the entire session.
*
* This information is available from sessions without loading the entire
* session into memory.
*/
public class SessionSummary implements ISessionSummary {
/**
* A default value for when the product name is unknown.
*/
public static final String UNKNOWN_PRODUCT = "Unknown Product";
/**
* A default value for when the application name is unknown.
*/
public static final String UNKNOWN_APPLICATION = "Unknown Application";
/** The is live. */
private boolean isLive;
/** The packet. */
private SessionSummaryPacket packet;
/** The critical count. */
private int criticalCount;
/** The error count. */
private int errorCount;
/** The warning count. */
private int warningCount;
/** The message count. */
private int messageCount;
/** The session status. */
volatile private SessionStatus sessionStatus;
/** The agent app type. */
private ApplicationType agentAppType;
/** The privacy enabled. */
private boolean privacyEnabled;
/**
* Create a new session summary as the live collection session for the current
* process
*
* This constructor figures out all of the summary information when invoked,
* which can take a moment.
*
* @param configuration the configuration
* @throws IOException Signals that an I/O exception has occurred.
*/
public SessionSummary(AgentConfiguration configuration) throws IOException {
this.isLive = true;
this.packet = new SessionSummaryPacket();
this.sessionStatus = SessionStatus.RUNNING;
this.privacyEnabled = configuration.getPublisher().getEnableAnonymousMode();
InetAddress host;
try {
host = InetAddress.getLocalHost();
} catch (UnknownHostException e1) {
throw e1;
}
try {
this.packet.setID(UUID.randomUUID());
this.packet.setCaption(null);
// this stuff all tends to succeed
if (this.privacyEnabled) {
this.packet.setUserName("");
this.packet.setUserDomainName("");
} else if (SystemUtils.isWindows()) {
this.packet.setUserName(TypeUtils.trimToEmpty(SystemUtils.getUserName()));
this.packet.setUserDomainName(TypeUtils.trimToEmpty(SystemUtils.getSystemProperty("USERDOMAIN")));
} else {
this.packet.setUserName(TypeUtils.trimToEmpty(SystemUtils.getUserName()));
this.packet.setUserDomainName(TypeUtils.trimToEmpty(host.getHostName()));
}
this.packet.setTimeZoneCaption(SystemUtils.getUserTimezone());
this.packet.setEndDateTime(getStartDateTime()); // we want to ALWAYS have an end time, and since we just
// created
// our start time we need to move that over to end time
// this stuff, on the other hand, doesn't always succeed
// Lets see if the user has already picked some things for us...
PublisherConfiguration publisherConfig = configuration.getPublisher();
String productName = null, applicationName = null, applicationDescription = null;
Version applicationVersion = null;
getApplicationType();
// what kind of process are we?
this.agentAppType = publisherConfig.getApplicationType();
if (this.agentAppType == ApplicationType.UNKNOWN) {
if (SystemUtils.isWindows()) {
this.agentAppType = ApplicationType.WINDOWS;
}
}
this.packet.setApplicationType(this.agentAppType); // Finally, set the application type from our determined
// type.
// OK, now apply configuration overrides or what we discovered...
this.packet.setProductName(TypeUtils.isBlank(publisherConfig.getProductName()) ? productName
: publisherConfig.getProductName());
this.packet.setApplicationName(TypeUtils.isBlank(publisherConfig.getApplicationName()) ? applicationName
: publisherConfig.getApplicationName());
this.packet.setApplicationVersion(
(publisherConfig.getApplicationVersion() != null) ? publisherConfig.getApplicationVersion()
: applicationVersion);
this.packet.setApplicationDescription(
TypeUtils.isBlank(publisherConfig.getApplicationDescription()) ? applicationDescription
: publisherConfig.getApplicationDescription());
this.packet.setEnvironmentName(publisherConfig.getEnvironmentName());
this.packet.setPromotionLevelName(publisherConfig.getPromotionLevelName());
// Finally, no nulls allowed! Fix any...
this.packet.setProductName(
TypeUtils.isBlank(this.packet.getProductName()) ? "Unknown" : this.packet.getProductName());
this.packet.setApplicationName(TypeUtils.isBlank(this.packet.getApplicationName()) ? "Unknown"
: this.packet.getApplicationName());
Version tempVar = this.packet.getApplicationVersion();
this.packet.setApplicationVersion((tempVar != null) ? tempVar : new Version(0, 0));
String tempVar2 = this.packet.getApplicationDescription();
this.packet.setApplicationDescription((tempVar2 != null) ? tempVar2 : "");
String tempVar3 = this.packet.getEnvironmentName();
this.packet.setEnvironmentName((tempVar3 != null) ? tempVar3 : "");
String tempVar4 = this.packet.getPromotionLevelName();
this.packet.setPromotionLevelName((tempVar4 != null) ? tempVar4 : "");
this.packet.setComputerId(getComputerIdSafe(this.packet.getProductName(), configuration));
this.packet.setAgentVersion(getAgentVersionSafe());
} catch (RuntimeException ex) {
// we really don't want an init error to fail us, not here!
}
if (!this.privacyEnabled) {
try {
this.packet.setHostName(host.getHostName());
this.packet.setDnsDomainName((host.getCanonicalHostName() != null) ? host.getCanonicalHostName() : "");
} catch (java.lang.Exception e) {
// fallback to environment names
try {
this.packet.setHostName(host.getHostName());
} catch (RuntimeException ex) {
// we really don't want an init error to fail us, not here!
this.packet.setHostName("unknown");
}
this.packet.setDnsDomainName("");
}
} else {
// Privacy mode. Don't store "personally-identifying information".
this.packet.setHostName("anonymous");
this.packet.setDnsDomainName("");
}
// TODO KENDALL - We want to add in the OS information if we can feasibly get
// it; this was dropped for .NET Core which is why it's missing here.
if (SystemUtils.isWindows()) {
this.packet.setOSPlatformCode(2); // Win32NT
this.packet.setOSServicePack(""); // BUG
} else if (SystemUtils.isLinux()) {
this.packet.setOSPlatformCode(4); // Unix
this.packet.setOSServicePack(""); // BUG
} else if (SystemUtils.isMacOsX()) {
this.packet.setOSPlatformCode(6); // OSX
this.packet.setOSServicePack(""); // BUG
}
this.packet.setOSVersion(new Version(SystemUtils.getOsVersion()));
try {
String arch = SystemUtils.getOsArch();
if (TypeUtils.isNotBlank(arch)) {
ProcessorArchitecture architecture = arch.endsWith("64") ? ProcessorArchitecture.AMD64
: ProcessorArchitecture.X86;
this.packet.setOSArchitecture(architecture);
this.packet.setRuntimeArchitecture(architecture);
}
this.packet.setOSCultureName(Locale.getDefault().getDisplayName());
this.packet.setCurrentCultureName(Locale.getDefault().getDisplayName());
this.packet.setCurrentUICultureName(Locale.getDefault().getDisplayName());
this.packet.setOSBootMode(OSBootMode.NORMAL);
this.packet.setRuntimeVersion(new Version(SystemUtils.getJavaVersion()));
this.packet.setProcessors(Runtime.getRuntime().availableProcessors());
this.packet.setProcessorCores(this.packet.getProcessors()); // BUG
this.packet.setMemoryMB(SystemUtils.getTotalMemory());
this.packet.setUserInteractive(false);
// find the active screen resolution
DisplayMode displayMode = SystemUtils.getDisplayMode();
if (displayMode != null) {
this.packet.setTerminalServer(false);
this.packet.setColorDepth(displayMode.getBitDepth());
this.packet.setScreenHeight(Double.valueOf(displayMode.getHeight()).intValue());
this.packet.setScreenWidth(Double.valueOf(displayMode.getWidth()).intValue());
}
if (this.privacyEnabled) {
this.packet.setCommandLine("");
} else {
try (StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer)){
System.getProperties().list(printWriter);
this.packet.setCommandLine(writer.getBuffer().toString());
}
}
} catch (Exception ex) {
// we really don't want an init error to fail us, not here!
}
// now do user defined properties
try {
for (Map.Entry