You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/08/15 13:41:56 UTC
[1/3] ignite git commit: IGNITE-1629 .NET: Introduced native logging
facility. This closes #786.
Repository: ignite
Updated Branches:
refs/heads/master bfa375bbc -> b911ff8eb
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
index e5e79cd..cb15564 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
@@ -23,6 +23,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
using System;
using System.Collections.Generic;
using System.ComponentModel;
+ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Apache.Ignite.Core.Binary;
@@ -35,6 +36,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
using Apache.Ignite.Core.Common;
using Apache.Ignite.Core.Impl.Binary;
using Apache.Ignite.Core.Impl.Cache.Affinity;
+ using Apache.Ignite.Core.Log;
/// <summary>
/// Defines grid cache configuration.
@@ -353,6 +355,21 @@ namespace Apache.Ignite.Core.Cache.Configuration
}
/// <summary>
+ /// Validates this instance and outputs information to the log, if necessary.
+ /// </summary>
+ internal void Validate(ILogger log)
+ {
+ Debug.Assert(log != null);
+
+ var entities = QueryEntities;
+ if (entities != null)
+ {
+ foreach (var entity in entities)
+ entity.Validate(log, string.Format("Validating cache configuration '{0}'", Name ?? ""));
+ }
+ }
+
+ /// <summary>
/// Gets or sets write synchronization mode. This mode controls whether the main
/// caller should wait for update on other nodes to complete or not.
/// </summary>
@@ -669,7 +686,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
/// <summary>
/// Gets or sets the affinity function to provide mapping from keys to nodes.
/// <para />
- /// Predefined implementations:
+ /// Predefined implementations:
/// <see cref="RendezvousAffinityFunction"/>, <see cref="FairAffinityFunction"/>.
/// </summary>
public IAffinityFunction AffinityFunction { get; set; }
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
index e6eceb8..adfe9e1 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
@@ -27,6 +27,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
using System.Reflection;
using Apache.Ignite.Core.Binary;
using Apache.Ignite.Core.Impl.Binary;
+ using Apache.Ignite.Core.Log;
/// <summary>
/// Query entity is a description of cache entry (composed of key and value)
@@ -104,7 +105,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
KeyTypeName = value == null
? null
- : (JavaTypes.GetJavaTypeNameAndLogWarning(value) ?? BinaryUtils.GetTypeName(value));
+ : (JavaTypes.GetJavaTypeName(value) ?? BinaryUtils.GetTypeName(value));
_keyType = value;
}
@@ -140,7 +141,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
ValueTypeName = value == null
? null
- : (JavaTypes.GetJavaTypeNameAndLogWarning(value) ?? BinaryUtils.GetTypeName(value));
+ : (JavaTypes.GetJavaTypeName(value) ?? BinaryUtils.GetTypeName(value));
_valueType = value;
}
@@ -239,6 +240,26 @@ namespace Apache.Ignite.Core.Cache.Configuration
writer.WriteInt(0);
}
+ /// <summary>
+ /// Validates this instance and outputs information to the log, if necessary.
+ /// </summary>
+ internal void Validate(ILogger log, string logInfo)
+ {
+ Debug.Assert(log != null);
+ Debug.Assert(logInfo != null);
+
+ logInfo += string.Format(", QueryEntity '{0}:{1}'", _keyTypeName ?? "", _valueTypeName ?? "");
+
+ JavaTypes.LogIndirectMappingWarning(_keyType, log, logInfo);
+ JavaTypes.LogIndirectMappingWarning(_valueType, log, logInfo);
+
+ var fields = Fields;
+ if (fields != null)
+ {
+ foreach (var field in fields)
+ field.Validate(log, logInfo);
+ }
+ }
/// <summary>
/// Rescans the attributes in <see cref="KeyType"/> and <see cref="ValueType"/>.
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryField.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryField.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryField.cs
index b11e53d..12028e2 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryField.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryField.cs
@@ -20,8 +20,10 @@
namespace Apache.Ignite.Core.Cache.Configuration
{
using System;
+ using System.Diagnostics;
using Apache.Ignite.Core.Impl.Binary;
using Apache.Ignite.Core.Impl.Common;
+ using Apache.Ignite.Core.Log;
/// <summary>
/// Represents a queryable field.
@@ -71,7 +73,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
}
/// <summary>
- /// Gets the field name.
+ /// Gets or sets the field name.
/// </summary>
public string Name { get; set; }
@@ -87,7 +89,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
{
FieldTypeName = value == null
? null
- : (JavaTypes.GetJavaTypeNameAndLogWarning(value) ?? BinaryUtils.GetTypeName(value));
+ : (JavaTypes.GetJavaTypeName(value) ?? BinaryUtils.GetTypeName(value));
_type = value;
}
@@ -105,5 +107,18 @@ namespace Apache.Ignite.Core.Cache.Configuration
_type = null;
}
}
+
+ /// <summary>
+ /// Validates this instance and outputs information to the log, if necessary.
+ /// </summary>
+ internal void Validate(ILogger log, string logInfo)
+ {
+ Debug.Assert(log != null);
+ Debug.Assert(logInfo != null);
+
+ logInfo += string.Format(", QueryField '{0}'", Name);
+
+ JavaTypes.LogIndirectMappingWarning(_type, log, logInfo);
+ }
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
index a16ae3a..91aa1dd 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
@@ -29,6 +29,7 @@ namespace Apache.Ignite.Core
using Apache.Ignite.Core.Datastream;
using Apache.Ignite.Core.DataStructures;
using Apache.Ignite.Core.Events;
+ using Apache.Ignite.Core.Log;
using Apache.Ignite.Core.Lifecycle;
using Apache.Ignite.Core.Messaging;
using Apache.Ignite.Core.Services;
@@ -277,6 +278,13 @@ namespace Apache.Ignite.Core
ICollection<string> GetCacheNames();
/// <summary>
+ /// Gets the logger.
+ /// <para />
+ /// See <see cref="IgniteConfiguration.Logger"/> for customization.
+ /// </summary>
+ ILogger Logger { get; }
+
+ /// <summary>
/// Occurs when node begins to stop. Node is fully functional at this point.
/// See also: <see cref="LifecycleEventType.BeforeNodeStop"/>.
/// </summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs
index e033ce0..7652092 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs
@@ -40,6 +40,7 @@
using Apache.Ignite.Core.Impl.Binary;
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Core.Lifecycle;
+ using Apache.Ignite.Core.Log;
using Apache.Ignite.Core.Transactions;
using BinaryReader = Apache.Ignite.Core.Impl.Binary.BinaryReader;
using BinaryWriter = Apache.Ignite.Core.Impl.Binary.BinaryWriter;
@@ -294,6 +295,21 @@
}
/// <summary>
+ /// Validates this instance and outputs information to the log, if necessary.
+ /// </summary>
+ internal void Validate(ILogger log)
+ {
+ Debug.Assert(log != null);
+
+ var ccfg = CacheConfiguration;
+ if (ccfg != null)
+ {
+ foreach (var cfg in ccfg)
+ cfg.Validate(log);
+ }
+ }
+
+ /// <summary>
/// Reads data from specified reader into current instance.
/// </summary>
/// <param name="r">The binary reader.</param>
@@ -400,6 +416,7 @@
Assemblies = cfg.Assemblies;
SuppressWarnings = cfg.SuppressWarnings;
LifecycleBeans = cfg.LifecycleBeans;
+ Logger = cfg.Logger;
JvmInitialMemoryMb = cfg.JvmInitialMemoryMb;
JvmMaxMemoryMb = cfg.JvmMaxMemoryMb;
}
@@ -743,5 +760,13 @@
return FromXml(xmlReader);
}
}
+
+ /// <summary>
+ /// Gets or sets the logger.
+ /// <para />
+ /// If no logger is set, logging is delegated to Java, which uses the logger defined in Spring XML (if present)
+ /// or logs to console otherwise.
+ /// </summary>
+ public ILogger Logger { get; set; }
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
index 47c3a98..40e3055 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
@@ -1095,6 +1095,18 @@
</xs:attribute>
</xs:complexType>
</xs:element>
+ <xs:element name="logger" minOccurs="0">
+ <xs:annotation>
+ <xs:documentation>The logger. If no logger is set, logging is delegated to Java, which uses the logger defined in Spring XML (if present) or logs to console otherwise.</xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required">
+ <xs:annotation>
+ <xs:documentation>Assembly-qualified type name.</xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
</xs:all>
<xs:attribute name="gridName" type="xs:string">
<xs:annotation>
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
index 552a7f2..7b023f3 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
@@ -35,9 +35,11 @@ namespace Apache.Ignite.Core
using Apache.Ignite.Core.Impl.Cache.Affinity;
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Core.Impl.Handle;
+ using Apache.Ignite.Core.Impl.Log;
using Apache.Ignite.Core.Impl.Memory;
using Apache.Ignite.Core.Impl.Unmanaged;
using Apache.Ignite.Core.Lifecycle;
+ using Apache.Ignite.Core.Log;
using Apache.Ignite.Core.Resource;
using BinaryReader = Apache.Ignite.Core.Impl.Binary.BinaryReader;
using UU = Apache.Ignite.Core.Impl.Unmanaged.UnmanagedUtils;
@@ -201,15 +203,21 @@ namespace Apache.Ignite.Core
lock (SyncRoot)
{
+ // 0. Init logger
+ var log = cfg.Logger ?? new JavaLogger();
+
+ log.Debug("Starting Ignite.NET " + Assembly.GetExecutingAssembly().GetName().Version);
+
// 1. Check GC settings.
- CheckServerGc(cfg);
+ CheckServerGc(cfg, log);
// 2. Create context.
- IgniteUtils.LoadDlls(cfg.JvmDllPath);
+ IgniteUtils.LoadDlls(cfg.JvmDllPath, log);
- var cbs = new UnmanagedCallbacks();
+ var cbs = new UnmanagedCallbacks(log);
- IgniteManager.CreateJvmContext(cfg, cbs);
+ IgniteManager.CreateJvmContext(cfg, cbs, log);
+ log.Debug("JVM started.");
var gridName = cfg.GridName;
@@ -221,12 +229,17 @@ namespace Apache.Ignite.Core
try
{
// 4. Initiate Ignite start.
- UU.IgnitionStart(cbs.Context, cfg.SpringConfigUrl, gridName, ClientMode);
+ UU.IgnitionStart(cbs.Context, cfg.SpringConfigUrl, gridName, ClientMode, cfg.Logger != null);
+
// 5. At this point start routine is finished. We expect STARTUP object to have all necessary data.
var node = _startup.Ignite;
interopProc = node.InteropProcessor;
+ var javaLogger = log as JavaLogger;
+ if (javaLogger != null)
+ javaLogger.SetProcessor(interopProc);
+
// 6. On-start callback (notify lifecycle components).
node.OnStart();
@@ -271,10 +284,11 @@ namespace Apache.Ignite.Core
/// Check whether GC is set to server mode.
/// </summary>
/// <param name="cfg">Configuration.</param>
- private static void CheckServerGc(IgniteConfiguration cfg)
+ /// <param name="log">Log.</param>
+ private static void CheckServerGc(IgniteConfiguration cfg, ILogger log)
{
if (!cfg.SuppressWarnings && !GCSettings.IsServerGC && Interlocked.CompareExchange(ref _gcWarn, 1, 0) == 0)
- Logger.LogWarning("GC server mode is not enabled, this could lead to less " +
+ log.Warn("GC server mode is not enabled, this could lead to less " +
"than optimal performance on multi-core machines (to enable see " +
"http://msdn.microsoft.com/en-us/library/ms229357(v=vs.110).aspx).");
}
@@ -285,14 +299,15 @@ namespace Apache.Ignite.Core
/// <param name="inStream">Input stream with data.</param>
/// <param name="outStream">Output stream.</param>
/// <param name="handleRegistry">Handle registry.</param>
- internal static void OnPrepare(PlatformMemoryStream inStream, PlatformMemoryStream outStream,
- HandleRegistry handleRegistry)
+ /// <param name="log">Log.</param>
+ internal static void OnPrepare(PlatformMemoryStream inStream, PlatformMemoryStream outStream,
+ HandleRegistry handleRegistry, ILogger log)
{
try
{
BinaryReader reader = BinaryUtils.Marshaller.StartUnmarshal(inStream);
- PrepareConfiguration(reader, outStream);
+ PrepareConfiguration(reader, outStream, log);
PrepareLifecycleBeans(reader, outStream, handleRegistry);
@@ -313,7 +328,8 @@ namespace Apache.Ignite.Core
/// </summary>
/// <param name="reader">Reader.</param>
/// <param name="outStream">Response stream.</param>
- private static void PrepareConfiguration(BinaryReader reader, PlatformMemoryStream outStream)
+ /// <param name="log">Log.</param>
+ private static void PrepareConfiguration(BinaryReader reader, PlatformMemoryStream outStream, ILogger log)
{
// 1. Load assemblies.
IgniteConfiguration cfg = _startup.Configuration;
@@ -334,6 +350,7 @@ namespace Apache.Ignite.Core
_startup.Marshaller = new Marshaller(cfg.BinaryConfiguration);
// 3. Send configuration details to Java
+ cfg.Validate(log);
cfg.Write(_startup.Marshaller.StartMarshal(outStream));
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
index f30264d..a8d94f2 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
@@ -20,7 +20,7 @@ namespace Apache.Ignite.Core.Impl.Binary
using System;
using System.Collections.Generic;
using System.Linq;
- using Apache.Ignite.Core.Impl.Common;
+ using Apache.Ignite.Core.Log;
/// <summary>
/// Provides mapping between Java and .NET basic types.
@@ -67,26 +67,33 @@ namespace Apache.Ignite.Core.Impl.Binary
/// <summary>
/// Gets the corresponding Java type name.
- /// Logs a warning for indirectly mapped types.
/// </summary>
- public static string GetJavaTypeNameAndLogWarning(Type type)
+ public static string GetJavaTypeName(Type type)
{
if (type == null)
return null;
string res;
- if (!NetToJava.TryGetValue(type, out res))
- return null;
+ return NetToJava.TryGetValue(type, out res) ? res : null;
+ }
- Type directType;
+ /// <summary>
+ /// Logs a warning for indirectly mapped types.
+ /// </summary>
+ public static void LogIndirectMappingWarning(Type type, ILogger log, string logInfo)
+ {
+ if (type == null)
+ return;
- if (IndirectMappingTypes.TryGetValue(type, out directType))
- Logger.LogWarning("Type '{0}' maps to Java type '{1}' using unchecked conversion. " +
- "This may cause issues in SQL queries. " +
- "You can use '{2}' instead to achieve direct mapping.", type, res, directType);
+ Type directType;
+ if (!IndirectMappingTypes.TryGetValue(type, out directType))
+ return;
- return res;
+ log.Warn("{0}: Type '{1}' maps to Java type '{2}' using unchecked conversion. " +
+ "This may cause issues in SQL queries. " +
+ "You can use '{3}' instead to achieve direct mapping.",
+ logInfo, type, NetToJava[type], directType);
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Logger.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Logger.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Logger.cs
deleted file mode 100644
index cab5afc..0000000
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/Logger.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-\ufeff/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace Apache.Ignite.Core.Impl.Common
-{
- using System;
-
- /// <summary>
- /// Console logger.
- /// </summary>
- internal static class Logger
- {
- /// <summary>
- /// Logs the warning.
- /// </summary>
- /// <param name="warning">The warning.</param>
- /// <param name="args">The arguments.</param>
- public static void LogWarning(string warning, params object[] args)
- {
- Console.WriteLine("WARNING: " + string.Format(warning, args));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
index d516056..6e89a86 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
@@ -43,6 +43,7 @@ namespace Apache.Ignite.Core.Impl
using Apache.Ignite.Core.Impl.Transactions;
using Apache.Ignite.Core.Impl.Unmanaged;
using Apache.Ignite.Core.Lifecycle;
+ using Apache.Ignite.Core.Log;
using Apache.Ignite.Core.Messaging;
using Apache.Ignite.Core.Services;
using Apache.Ignite.Core.Transactions;
@@ -401,6 +402,7 @@ namespace Apache.Ignite.Core.Impl
NearCacheConfiguration nearConfiguration)
{
IgniteArgumentCheck.NotNull(configuration, "configuration");
+ configuration.Validate(Logger);
using (var stream = IgniteManager.Memory.Allocate().GetStream())
{
@@ -439,6 +441,7 @@ namespace Apache.Ignite.Core.Impl
NearCacheConfiguration nearConfiguration)
{
IgniteArgumentCheck.NotNull(configuration, "configuration");
+ configuration.Validate(Logger);
using (var stream = IgniteManager.Memory.Allocate().GetStream())
{
@@ -666,6 +669,12 @@ namespace Apache.Ignite.Core.Impl
}
/** <inheritdoc /> */
+ public ILogger Logger
+ {
+ get { return _cbs.Log; }
+ }
+
+ /** <inheritdoc /> */
public event EventHandler Stopping;
/** <inheritdoc /> */
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
index 05bc786..ee54218 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
@@ -27,6 +27,7 @@ namespace Apache.Ignite.Core.Impl
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Core.Impl.Memory;
using Apache.Ignite.Core.Impl.Unmanaged;
+ using Apache.Ignite.Core.Log;
using UU = Apache.Ignite.Core.Impl.Unmanaged.UnmanagedUtils;
/// <summary>
@@ -57,8 +58,9 @@ namespace Apache.Ignite.Core.Impl
/// </summary>
/// <param name="cfg">Configuration.</param>
/// <param name="cbs">Callbacks.</param>
+ /// <param name="log"></param>
/// <returns>Context.</returns>
- internal static void CreateJvmContext(IgniteConfiguration cfg, UnmanagedCallbacks cbs)
+ internal static void CreateJvmContext(IgniteConfiguration cfg, UnmanagedCallbacks cbs, ILogger log)
{
lock (SyncRoot)
{
@@ -69,7 +71,7 @@ namespace Apache.Ignite.Core.Impl
{
if (!_jvmCfg.Equals(jvmCfg))
{
- Logger.LogWarning("Attempting to start Ignite node with different Java " +
+ log.Warn("Attempting to start Ignite node with different Java " +
"configuration; current Java configuration will be ignored (consider " +
"starting node in separate process) [oldConfig=" + _jvmCfg +
", newConfig=" + jvmCfg + ']');
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
index 949d31c..ef811f5 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
@@ -31,6 +31,7 @@ namespace Apache.Ignite.Core.Impl
using Apache.Ignite.Core.Events;
using Apache.Ignite.Core.Impl.Binary;
using Apache.Ignite.Core.Impl.Cluster;
+ using Apache.Ignite.Core.Log;
using Apache.Ignite.Core.Lifecycle;
using Apache.Ignite.Core.Messaging;
using Apache.Ignite.Core.Services;
@@ -386,6 +387,12 @@ namespace Apache.Ignite.Core.Impl
}
/** <inheritdoc /> */
+ public ILogger Logger
+ {
+ get { return _ignite.Logger; }
+ }
+
+ /** <inheritdoc /> */
public event EventHandler Stopping
{
add { _ignite.Stopping += value; }
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
index 048c8ac..70d483d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
@@ -35,6 +35,7 @@ namespace Apache.Ignite.Core.Impl
using Apache.Ignite.Core.Impl.Cluster;
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Core.Impl.Unmanaged;
+ using Apache.Ignite.Core.Log;
using Microsoft.Win32;
using BinaryReader = Apache.Ignite.Core.Impl.Binary.BinaryReader;
@@ -124,12 +125,17 @@ namespace Apache.Ignite.Core.Impl
/// Load JVM DLL if needed.
/// </summary>
/// <param name="configJvmDllPath">JVM DLL path from config.</param>
- public static void LoadDlls(string configJvmDllPath)
+ /// <param name="log">Log.</param>
+ public static void LoadDlls(string configJvmDllPath, ILogger log)
{
- if (_loaded) return;
+ if (_loaded)
+ {
+ log.Debug("JNI dll is already loaded.");
+ return;
+ }
// 1. Load JNI dll.
- LoadJvmDll(configJvmDllPath);
+ LoadJvmDll(configJvmDllPath, log);
// 2. Load GG JNI dll.
UnmanagedUtils.Initialize();
@@ -190,17 +196,25 @@ namespace Apache.Ignite.Core.Impl
/// <summary>
/// Loads the JVM DLL.
/// </summary>
- private static void LoadJvmDll(string configJvmDllPath)
+ private static void LoadJvmDll(string configJvmDllPath, ILogger log)
{
var messages = new List<string>();
foreach (var dllPath in GetJvmDllPaths(configJvmDllPath))
{
+ log.Debug("Trying to load JVM dll from [option={0}, path={1}]...", dllPath.Key, dllPath.Value);
+
var errCode = LoadDll(dllPath.Value, FileJvmDll);
if (errCode == 0)
+ {
+ log.Debug("jvm.dll successfully loaded from [option={0}, path={1}]", dllPath.Key, dllPath.Value);
return;
+ }
+
+ var message = string.Format(CultureInfo.InvariantCulture, "[option={0}, path={1}, error={2}]",
+ dllPath.Key, dllPath.Value, FormatWin32Error(errCode));
+ messages.Add(message);
- messages.Add(string.Format(CultureInfo.InvariantCulture, "[option={0}, path={1}, error={2}]",
- dllPath.Key, dllPath.Value, FormatWin32Error(errCode)));
+ log.Debug("Failed to load jvm.dll: " + message);
if (dllPath.Value == configJvmDllPath)
break; // if configJvmDllPath is specified and is invalid - do not try other options
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Log/JavaLogger.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Log/JavaLogger.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Log/JavaLogger.cs
new file mode 100644
index 0000000..23e7a37
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Log/JavaLogger.cs
@@ -0,0 +1,110 @@
+\ufeff/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl.Log
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Linq;
+ using Apache.Ignite.Core.Impl.Unmanaged;
+ using Apache.Ignite.Core.Log;
+
+ /// <summary>
+ /// Logger that delegates to Java.
+ /// </summary>
+ internal class JavaLogger : ILogger
+ {
+ /** */
+ private IUnmanagedTarget _proc;
+
+ /** */
+ private readonly List<LogLevel> _enabledLevels = new List<LogLevel>(5);
+
+ /** */
+ private readonly List<Tuple<LogLevel, string, string, string>> _pendingLogs
+ = new List<Tuple<LogLevel, string, string, string>>();
+
+ /** */
+ private readonly object _syncRoot = new object();
+
+ /// <summary>
+ /// Sets the processor.
+ /// </summary>
+ /// <param name="proc">The proc.</param>
+ public void SetProcessor(IUnmanagedTarget proc)
+ {
+ Debug.Assert(proc != null);
+
+ lock (_syncRoot)
+ {
+ _proc = proc;
+
+ // Preload enabled levels.
+ _enabledLevels.AddRange(
+ new[] { LogLevel.Trace, LogLevel.Debug, LogLevel.Info, LogLevel.Warn, LogLevel.Error }
+ .Where(x => UnmanagedUtils.ProcessorLoggerIsLevelEnabled(proc, (int)x)));
+
+ foreach (var log in _pendingLogs)
+ {
+ Log(log.Item1, log.Item2, log.Item3, log.Item4);
+ }
+ }
+ }
+
+ /** <inheritdoc /> */
+ public void Log(LogLevel level, string message, object[] args, IFormatProvider formatProvider, string category,
+ string nativeErrorInfo, Exception ex)
+ {
+ // Java error info should not go back to Java.
+ // Either we log in .NET, and Java sends us logs, or we log in Java, and .NET sends logs, not both.
+ Debug.Assert(nativeErrorInfo == null);
+
+ lock (_syncRoot)
+ {
+ if (!IsEnabled(level))
+ return;
+
+ var msg = args == null ? message : string.Format(formatProvider, message, args);
+ var err = ex != null ? ex.ToString() : null;
+
+ if (_proc != null)
+ Log(level, msg, category, err);
+ else
+ _pendingLogs.Add(Tuple.Create(level, msg, category, err));
+ }
+ }
+
+ /** <inheritdoc /> */
+ public bool IsEnabled(LogLevel level)
+ {
+ lock (_syncRoot)
+ {
+ return _proc == null || _enabledLevels.Contains(level);
+ }
+ }
+
+ /// <summary>
+ /// Logs the message.
+ /// </summary>
+ private void Log(LogLevel level, string msg, string category, string err)
+ {
+ if (IsEnabled(level))
+ UnmanagedUtils.ProcessorLoggerLog(_proc, (int)level, msg, category, err);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
index 2da4192..8756dec 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
@@ -113,6 +113,13 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
[DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetCacheNames")]
public static extern void ProcessorGetCacheNames(void* ctx, void* obj, long memPtr);
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorLoggerIsLevelEnabled")]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool ProcessorLoggerIsLevelEnabled(void* ctx, void* obj, int level);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorLoggerLog")]
+ public static extern void ProcessorLoggerLog(void* ctx, void* obj, int level, sbyte* messsage, sbyte* category, sbyte* errorInfo);
+
[DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInStreamOutLong")]
public static extern long TargetInStreamOutLong(void* ctx, void* target, int opType, long memPtr);
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs
index 51d9c74..6367e1e 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbackHandlers.cs
@@ -104,5 +104,8 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
internal void* affinityFunctionAssignPartitions;
internal void* affinityFunctionRemoveNode;
internal void* affinityFunctionDestroy;
+
+ internal void* loggerLog;
+ internal void* loggerIsLevelEnabled;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs
index b1c840f..2f70426 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs
@@ -21,6 +21,7 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+ using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading;
using Apache.Ignite.Core.Cache.Affinity;
@@ -37,11 +38,13 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
using Apache.Ignite.Core.Impl.Datastream;
using Apache.Ignite.Core.Impl.Events;
using Apache.Ignite.Core.Impl.Handle;
+ using Apache.Ignite.Core.Impl.Log;
using Apache.Ignite.Core.Impl.Memory;
using Apache.Ignite.Core.Impl.Messaging;
using Apache.Ignite.Core.Impl.Resource;
using Apache.Ignite.Core.Impl.Services;
using Apache.Ignite.Core.Lifecycle;
+ using Apache.Ignite.Core.Log;
using Apache.Ignite.Core.Services;
using UU = UnmanagedUtils;
@@ -88,6 +91,9 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")]
private readonly IntPtr _cbsPtr;
+ /** Log. */
+ private readonly ILogger _log;
+
/** Error type: generic. */
private const int ErrGeneric = 1;
@@ -97,7 +103,7 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
/** Error type: attach. */
private const int ErrJvmAttach = 3;
- /** Opeartion: prepare .Net. */
+ /** Operation: prepare .Net. */
private const int OpPrepareDotNet = 1;
private delegate long CacheStoreCreateCallbackDelegate(void* target, long memPtr);
@@ -173,6 +179,9 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
private delegate void OnClientDisconnectedDelegate(void* target);
private delegate void OnClientReconnectedDelegate(void* target, bool clusterRestarted);
+ private delegate void LoggerLogDelegate(void* target, int level, sbyte* messageChars, int messageCharsLen, sbyte* categoryChars, int categoryCharsLen, sbyte* errorInfoChars, int errorInfoCharsLen, long memPtr);
+ private delegate bool LoggerIsLevelEnabledDelegate(void* target, int level);
+
private delegate long AffinityFunctionInitDelegate(void* target, long memPtr, void* baseFunc);
private delegate int AffinityFunctionPartitionDelegate(void* target, long ptr, long memPtr);
private delegate void AffinityFunctionAssignPartitionsDelegate(void* target, long ptr, long inMemPtr, long outMemPtr);
@@ -182,10 +191,14 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
private delegate void ConsoleWriteDelegate(sbyte* chars, int charsLen, bool isErr);
/// <summary>
- /// constructor.
+ /// Constructor.
/// </summary>
- public UnmanagedCallbacks()
+ /// <param name="log">Logger.</param>
+ public UnmanagedCallbacks(ILogger log)
{
+ Debug.Assert(log != null);
+ _log = log;
+
var cbs = new UnmanagedCallbackHandlers
{
target = IntPtr.Zero.ToPointer(), // Target is not used in .Net as we rely on dynamic FP creation.
@@ -269,7 +282,10 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
affinityFunctionPartition = CreateFunctionPointer((AffinityFunctionPartitionDelegate)AffinityFunctionPartition),
affinityFunctionAssignPartitions = CreateFunctionPointer((AffinityFunctionAssignPartitionsDelegate)AffinityFunctionAssignPartitions),
affinityFunctionRemoveNode = CreateFunctionPointer((AffinityFunctionRemoveNodeDelegate)AffinityFunctionRemoveNode),
- affinityFunctionDestroy = CreateFunctionPointer((AffinityFunctionDestroyDelegate)AffinityFunctionDestroy)
+ affinityFunctionDestroy = CreateFunctionPointer((AffinityFunctionDestroyDelegate)AffinityFunctionDestroy),
+
+ loggerLog = CreateFunctionPointer((LoggerLogDelegate)LoggerLog),
+ loggerIsLevelEnabled = CreateFunctionPointer((LoggerIsLevelEnabledDelegate)LoggerIsLevelEnabled)
};
_cbsPtr = Marshal.AllocHGlobal(UU.HandlersSize());
@@ -537,7 +553,7 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
}
/// <summary>
- /// Get comptue job using it's GC handle pointer.
+ /// Get compute job using it's GC handle pointer.
/// </summary>
/// <param name="jobPtr">Job pointer.</param>
/// <returns>Compute job.</returns>
@@ -869,7 +885,7 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
using (var inStream = IgniteManager.Memory.Get(arg1).GetStream())
using (var outStream = IgniteManager.Memory.Get(arg2).GetStream())
{
- Ignition.OnPrepare(inStream, outStream, _handleRegistry);
+ Ignition.OnPrepare(inStream, outStream, _handleRegistry, _log);
return 0;
}
@@ -1117,6 +1133,40 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
});
}
+ private void LoggerLog(void* target, int level, sbyte* messageChars, int messageCharsLen, sbyte* categoryChars,
+ int categoryCharsLen, sbyte* errorInfoChars, int errorInfoCharsLen, long memPtr)
+ {
+ // When custom logger in .NET is not defined, Java should not call us.
+ Debug.Assert(!(_log is JavaLogger));
+
+ SafeCall(() =>
+ {
+ var message = IgniteUtils.Utf8UnmanagedToString(messageChars, messageCharsLen);
+ var category = IgniteUtils.Utf8UnmanagedToString(categoryChars, categoryCharsLen);
+ var nativeError = IgniteUtils.Utf8UnmanagedToString(errorInfoChars, errorInfoCharsLen);
+
+ Exception ex = null;
+
+ if (memPtr != 0 && _ignite != null)
+ {
+ using (var stream = IgniteManager.Memory.Get(memPtr).GetStream())
+ {
+ ex = _ignite.Marshaller.Unmarshal<Exception>(stream);
+ }
+ }
+
+ _log.Log((LogLevel) level, message, null, CultureInfo.InvariantCulture, category, nativeError, ex);
+ }, true);
+ }
+
+ private bool LoggerIsLevelEnabled(void* target, int level)
+ {
+ // When custom logger in .NET is not defined, Java should not call us.
+ Debug.Assert(!(_log is JavaLogger));
+
+ return SafeCall(() => _log.IsEnabled((LogLevel) level), true);
+ }
+
private static void ConsoleWrite(sbyte* chars, int charsLen, bool isErr)
{
try
@@ -1232,6 +1282,8 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
}
catch (Exception e)
{
+ _log.Error(e, "Failure in Java callback");
+
UU.ThrowToJava(_ctx.NativeContext, e);
}
}
@@ -1248,6 +1300,8 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
}
catch (Exception e)
{
+ _log.Error(e, "Failure in Java callback");
+
UU.ThrowToJava(_ctx.NativeContext, e);
return default(T);
@@ -1273,6 +1327,14 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
}
/// <summary>
+ /// Gets the log.
+ /// </summary>
+ public ILogger Log
+ {
+ get { return _log; }
+ }
+
+ /// <summary>
/// Create function pointer for the given function.
/// </summary>
private void* CreateFunctionPointer(Delegate del)
@@ -1309,6 +1371,8 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
}
_initEvent.Set();
+
+ ResourceProcessor.Inject(_log, grid);
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
index 0e9556d..f89caa8 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
@@ -77,11 +77,12 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
#region NATIVE METHODS: PROCESSOR
internal static void IgnitionStart(UnmanagedContext ctx, string cfgPath, string gridName,
- bool clientMode)
+ bool clientMode, bool userLogger)
{
using (var mem = IgniteManager.Memory.Allocate().GetStream())
{
mem.WriteBool(clientMode);
+ mem.WriteBool(userLogger);
sbyte* cfgPath0 = IgniteUtils.StringToUtf8Unmanaged(cfgPath);
sbyte* gridName0 = IgniteUtils.StringToUtf8Unmanaged(gridName);
@@ -377,6 +378,30 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
JNI.ProcessorGetCacheNames(target.Context, target.Target, memPtr);
}
+ internal static bool ProcessorLoggerIsLevelEnabled(IUnmanagedTarget target, int level)
+ {
+ return JNI.ProcessorLoggerIsLevelEnabled(target.Context, target.Target, level);
+ }
+
+ internal static void ProcessorLoggerLog(IUnmanagedTarget target, int level, string message, string category,
+ string errorInfo)
+ {
+ var message0 = IgniteUtils.StringToUtf8Unmanaged(message);
+ var category0 = IgniteUtils.StringToUtf8Unmanaged(category);
+ var errorInfo0 = IgniteUtils.StringToUtf8Unmanaged(errorInfo);
+
+ try
+ {
+ JNI.ProcessorLoggerLog(target.Context, target.Target, level, message0, category0, errorInfo0);
+ }
+ finally
+ {
+ Marshal.FreeHGlobal(new IntPtr(message0));
+ Marshal.FreeHGlobal(new IntPtr(category0));
+ Marshal.FreeHGlobal(new IntPtr(errorInfo0));
+ }
+ }
+
#endregion
#region NATIVE METHODS: TARGET
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Log/CategoryLogger.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Log/CategoryLogger.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Log/CategoryLogger.cs
new file mode 100644
index 0000000..2d7f876
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Log/CategoryLogger.cs
@@ -0,0 +1,82 @@
+\ufeff/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Log
+{
+ using System;
+ using Apache.Ignite.Core.Impl.Common;
+
+ /// <summary>
+ /// Wrapping logger with a predefined category.
+ /// <para />
+ /// When <see cref="Log"/> method is called, and <c>category</c> parameter is null, predefined category
+ /// will be used.
+ /// </summary>
+ public class CategoryLogger : ILogger
+ {
+ /** Wrapped logger. */
+ private readonly ILogger _logger;
+
+ /** Category to use. */
+ private readonly string _category;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CategoryLogger"/> class.
+ /// </summary>
+ /// <param name="logger">The logger to wrap.</param>
+ /// <param name="category">The category.</param>
+ public CategoryLogger(ILogger logger, string category)
+ {
+ IgniteArgumentCheck.NotNull(logger, "log");
+
+ // If logger is already a CategoryLogger, get underlying logger instead to avoid unnecessary nesting.
+ var catLogger = logger as CategoryLogger;
+ _logger = catLogger != null ? catLogger._logger : logger;
+
+ _category = category;
+ }
+
+ /// <summary>
+ /// Logs the specified message.
+ /// </summary>
+ /// <param name="level">The level.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments to format <paramref name="message" />.
+ /// Can be null (formatting will not occur).</param>
+ /// <param name="formatProvider">The format provider. Can be null if <paramref name="args" /> is null.</param>
+ /// <param name="category">The logging category name.</param>
+ /// <param name="nativeErrorInfo">The native error information.</param>
+ /// <param name="ex">The exception. Can be null.</param>
+ public void Log(LogLevel level, string message, object[] args, IFormatProvider formatProvider, string category,
+ string nativeErrorInfo, Exception ex)
+ {
+ _logger.Log(level, message, args, formatProvider, category ?? _category, nativeErrorInfo, ex);
+ }
+
+ /// <summary>
+ /// Determines whether the specified log level is enabled.
+ /// </summary>
+ /// <param name="level">The level.</param>
+ /// <returns>
+ /// Value indicating whether the specified log level is enabled
+ /// </returns>
+ public bool IsEnabled(LogLevel level)
+ {
+ return _logger.IsEnabled(level);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Log/ILogger.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Log/ILogger.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Log/ILogger.cs
new file mode 100644
index 0000000..a2f2f20
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Log/ILogger.cs
@@ -0,0 +1,51 @@
+\ufeff/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Log
+{
+ using System;
+
+ /// <summary>
+ /// Defines Ignite logging interface.
+ /// <para />
+ /// This interface only provides essential log methods.
+ /// All convenience overloads are in <see cref="LoggerExtensions"/>.
+ /// </summary>
+ public interface ILogger
+ {
+ /// <summary>
+ /// Logs the specified message.
+ /// </summary>
+ /// <param name="level">The level.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments to format <paramref name="message" />.
+ /// Can be null (formatting will not occur).</param>
+ /// <param name="formatProvider">The format provider. Can be null if <paramref name="args" /> is null.</param>
+ /// <param name="category">The logging category name.</param>
+ /// <param name="nativeErrorInfo">The native error information.</param>
+ /// <param name="ex">The exception. Can be null.</param>
+ void Log(LogLevel level, string message, object[] args, IFormatProvider formatProvider, string category,
+ string nativeErrorInfo, Exception ex);
+
+ /// <summary>
+ /// Determines whether the specified log level is enabled.
+ /// </summary>
+ /// <param name="level">The level.</param>
+ /// <returns>Value indicating whether the specified log level is enabled</returns>
+ bool IsEnabled(LogLevel level);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Log/LogLevel.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Log/LogLevel.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Log/LogLevel.cs
new file mode 100644
index 0000000..75694ab
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Log/LogLevel.cs
@@ -0,0 +1,53 @@
+\ufeff/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Log
+{
+ using System;
+
+ /// <summary>
+ /// Defines log levels.
+ /// </summary>
+ [Serializable]
+ public enum LogLevel
+ {
+ /// <summary>
+ /// Trace log level.
+ /// </summary>
+ Trace = 0,
+
+ /// <summary>
+ /// Debug log level.
+ /// </summary>
+ Debug = 1,
+
+ /// <summary>
+ /// Info log level.
+ /// </summary>
+ Info = 2,
+
+ /// <summary>
+ /// Warning log level.
+ /// </summary>
+ Warn = 3,
+
+ /// <summary>
+ /// Error log level.
+ /// </summary>
+ Error = 4
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Log/LoggerExtensions.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Log/LoggerExtensions.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Log/LoggerExtensions.cs
new file mode 100644
index 0000000..93748e3
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Log/LoggerExtensions.cs
@@ -0,0 +1,320 @@
+\ufeff/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Log
+{
+ using System;
+ using System.Globalization;
+ using Apache.Ignite.Core.Impl.Common;
+
+ /// <summary>
+ /// Extension methods for <see cref="ILogger" />
+ /// </summary>
+ public static class LoggerExtensions
+ {
+ // 4 overloads per level (message, message+args, ex+message, ex+message+args)
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Trace"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ public static void Trace(this ILogger logger, string message)
+ {
+ Log(logger, LogLevel.Trace, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Trace"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Trace(this ILogger logger, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Trace, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Trace"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ public static void Trace(this ILogger logger, Exception ex, string message)
+ {
+ Log(logger, LogLevel.Trace, ex, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Trace"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Trace(this ILogger logger, Exception ex, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Trace, ex, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Debug"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ public static void Debug(this ILogger logger, string message)
+ {
+ Log(logger, LogLevel.Debug, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Debug"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Debug(this ILogger logger, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Debug, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Debug"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ public static void Debug(this ILogger logger, Exception ex, string message)
+ {
+ Log(logger, LogLevel.Debug, ex, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Debug"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Debug(this ILogger logger, Exception ex, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Debug, ex, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Info"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ public static void Info(this ILogger logger, string message)
+ {
+ Log(logger, LogLevel.Info, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Info"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Info(this ILogger logger, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Info, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Info"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ public static void Info(this ILogger logger, Exception ex, string message)
+ {
+ Log(logger, LogLevel.Info, ex, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Info"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Info(this ILogger logger, Exception ex, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Info, ex, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Warn"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ public static void Warn(this ILogger logger, string message)
+ {
+ Log(logger, LogLevel.Warn, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Warn"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Warn(this ILogger logger, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Warn, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Warn"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ public static void Warn(this ILogger logger, Exception ex, string message)
+ {
+ Log(logger, LogLevel.Warn, ex, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Warn"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Warn(this ILogger logger, Exception ex, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Warn, ex, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Error"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ public static void Error(this ILogger logger, string message)
+ {
+ Log(logger, LogLevel.Error, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Error"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Error(this ILogger logger, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Error, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Error"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ public static void Error(this ILogger logger, Exception ex, string message)
+ {
+ Log(logger, LogLevel.Error, ex, message);
+ }
+
+ /// <summary>
+ /// Logs the message with <see cref="LogLevel.Error"/> level.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Error(this ILogger logger, Exception ex, string message, params object[] args)
+ {
+ Log(logger, LogLevel.Error, ex, message, args);
+ }
+
+ /// <summary>
+ /// Logs the message.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="level">The level.</param>
+ /// <param name="message">The message.</param>
+ public static void Log(this ILogger logger, LogLevel level, string message)
+ {
+ IgniteArgumentCheck.NotNull(logger, "logger");
+
+ logger.Log(level, message, null, null, null, null, null);
+ }
+
+ /// <summary>
+ /// Logs the message.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="level">The level.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Log(this ILogger logger, LogLevel level, string message, params object[] args)
+ {
+ IgniteArgumentCheck.NotNull(logger, "logger");
+
+ logger.Log(level, message, args, CultureInfo.InvariantCulture, null, null, null);
+ }
+
+ /// <summary>
+ /// Logs the message.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="level">The level.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ public static void Log(this ILogger logger, LogLevel level, Exception ex, string message)
+ {
+ IgniteArgumentCheck.NotNull(logger, "logger");
+
+ logger.Log(level, message, null, null, null, null, ex);
+ }
+
+ /// <summary>
+ /// Logs the message.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="level">The level.</param>
+ /// <param name="ex">The exception.</param>
+ /// <param name="message">The message.</param>
+ /// <param name="args">The arguments.</param>
+ public static void Log(this ILogger logger, LogLevel level, Exception ex, string message, params object[] args)
+ {
+ IgniteArgumentCheck.NotNull(logger, "logger");
+
+ logger.Log(level, message, args, CultureInfo.InvariantCulture, null, null, ex);
+ }
+
+ /// <summary>
+ /// Gets the <see cref="CategoryLogger"/> with a specified category that wraps provided logger.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="category">The category.</param>
+ /// <returns>Logger that always uses specified category.</returns>
+ public static ILogger GetLogger(this ILogger logger, string category)
+ {
+ IgniteArgumentCheck.NotNull(logger, "logger");
+
+ return new CategoryLogger(logger, category);
+ }
+ }
+}
\ No newline at end of file
[2/3] ignite git commit: IGNITE-1629 .NET: Introduced native logging
facility. This closes #786.
Posted by vo...@apache.org.
IGNITE-1629 .NET: Introduced native logging facility. This closes #786.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/165c0cf9
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/165c0cf9
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/165c0cf9
Branch: refs/heads/master
Commit: 165c0cf98ad788c5c0b9cd0210489a0cfd904d93
Parents: c154a08
Author: ptupitsyn <pt...@gridgain.com>
Authored: Mon Aug 15 16:40:24 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Aug 15 16:40:24 2016 +0300
----------------------------------------------------------------------
.../logger/platform/PlatformLogger.java | 223 ++++++++++
.../platform/PlatformAbstractBootstrap.java | 18 +-
.../platform/PlatformConfigurationEx.java | 6 +
.../platform/PlatformNoopProcessor.java | 10 +
.../processors/platform/PlatformProcessor.java | 16 +
.../platform/PlatformProcessorImpl.java | 56 +++
.../callback/PlatformCallbackGateway.java | 45 ++
.../callback/PlatformCallbackUtils.java | 20 +
.../cpp/PlatformCppConfigurationEx.java | 6 +
.../dotnet/PlatformDotNetBootstrap.java | 9 +
.../PlatformDotNetConfigurationClosure.java | 11 +-
.../dotnet/PlatformDotNetConfigurationEx.java | 12 +-
.../cpp/jni/include/ignite/jni/exports.h | 2 +
.../platforms/cpp/jni/include/ignite/jni/java.h | 13 +
modules/platforms/cpp/jni/project/vs/module.def | 3 +-
modules/platforms/cpp/jni/src/exports.cpp | 12 +-
modules/platforms/cpp/jni/src/java.cpp | 72 +++-
.../Apache.Ignite.Core.Tests.csproj | 8 +
.../Binary/BinaryStringTest.cs | 26 +-
.../Config/Log/custom-log.xml | 50 +++
.../Config/Log/dotnet-log4j.xml | 143 ++++++
.../IgniteConfigurationSerializerTest.cs | 24 ++
.../Log/CustomLoggerTest.cs | 430 +++++++++++++++++++
.../Log/DefaultLoggerTest.cs | 114 +++++
.../Apache.Ignite.Core.Tests/TestUtils.cs | 27 +-
.../Apache.Ignite.Core.csproj | 6 +-
.../Cache/Configuration/CacheConfiguration.cs | 19 +-
.../Cache/Configuration/QueryEntity.cs | 25 +-
.../Cache/Configuration/QueryField.cs | 19 +-
.../dotnet/Apache.Ignite.Core/IIgnite.cs | 8 +
.../Apache.Ignite.Core/IgniteConfiguration.cs | 25 ++
.../IgniteConfigurationSection.xsd | 12 +
.../dotnet/Apache.Ignite.Core/Ignition.cs | 39 +-
.../Apache.Ignite.Core/Impl/Binary/JavaTypes.cs | 29 +-
.../Apache.Ignite.Core/Impl/Common/Logger.cs | 37 --
.../dotnet/Apache.Ignite.Core/Impl/Ignite.cs | 9 +
.../Apache.Ignite.Core/Impl/IgniteManager.cs | 6 +-
.../Apache.Ignite.Core/Impl/IgniteProxy.cs | 7 +
.../Apache.Ignite.Core/Impl/IgniteUtils.cs | 26 +-
.../Apache.Ignite.Core/Impl/Log/JavaLogger.cs | 110 +++++
.../Impl/Unmanaged/IgniteJniNativeMethods.cs | 7 +
.../Impl/Unmanaged/UnmanagedCallbackHandlers.cs | 3 +
.../Impl/Unmanaged/UnmanagedCallbacks.cs | 76 +++-
.../Impl/Unmanaged/UnmanagedUtils.cs | 27 +-
.../Apache.Ignite.Core/Log/CategoryLogger.cs | 82 ++++
.../dotnet/Apache.Ignite.Core/Log/ILogger.cs | 51 +++
.../dotnet/Apache.Ignite.Core/Log/LogLevel.cs | 53 +++
.../Apache.Ignite.Core/Log/LoggerExtensions.cs | 320 ++++++++++++++
48 files changed, 2241 insertions(+), 111 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java b/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java
new file mode 100644
index 0000000..0a0437e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.logger.platform;
+
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.processors.platform.PlatformContext;
+import org.apache.ignite.internal.processors.platform.PlatformNativeException;
+import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway;
+import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
+import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
+import org.apache.ignite.internal.util.typedef.X;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET;
+
+/**
+ * Logger that delegates to platform.
+ */
+public class PlatformLogger implements IgniteLogger {
+ /** */
+ public static final int LVL_TRACE = 0;
+
+ /** */
+ public static final int LVL_DEBUG = 1;
+
+ /** */
+ public static final int LVL_INFO = 2;
+
+ /** */
+ public static final int LVL_WARN = 3;
+
+ /** */
+ public static final int LVL_ERROR = 4;
+
+ /** Callbacks. */
+ private volatile PlatformCallbackGateway gate;
+
+ /** Context. */
+ private volatile PlatformContext ctx;
+
+ /** Category. */
+ private final String category;
+
+ /** Trace flag. */
+ private volatile boolean traceEnabled;
+
+ /** Debug flag. */
+ private volatile boolean debugEnabled;
+
+ /** Info flag. */
+ private volatile boolean infoEnabled;
+
+ /** Quiet flag. */
+ private static final boolean isQuiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
+
+ /**
+ * Ctor.
+ *
+ */
+ public PlatformLogger() {
+ category = null;
+ }
+
+ /**
+ * Ctor.
+ */
+ private PlatformLogger(PlatformCallbackGateway gate, PlatformContext ctx, String category,
+ boolean traceEnabled, boolean debugEnabled, boolean infoEnabled) {
+ this.gate = gate;
+ this.ctx = ctx;
+ this.category = category;
+ this.traceEnabled = traceEnabled;
+ this.debugEnabled = debugEnabled;
+ this.infoEnabled = infoEnabled;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteLogger getLogger(Object ctgr) {
+ return new PlatformLogger(gate, ctx, getCategoryString(ctgr), traceEnabled, debugEnabled, infoEnabled);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void trace(String msg) {
+ log(LVL_TRACE, msg, null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void debug(String msg) {
+ log(LVL_DEBUG, msg, null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void info(String msg) {
+ log(LVL_INFO, msg, null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void warning(String msg) {
+ log(LVL_WARN, msg, null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void warning(String msg, @Nullable Throwable e) {
+ log(LVL_WARN, msg, e);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void error(String msg) {
+ log(LVL_ERROR, msg, null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void error(String msg, @Nullable Throwable e) {
+ log(LVL_ERROR, msg, e);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isTraceEnabled() {
+ return traceEnabled;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isDebugEnabled() {
+ return debugEnabled;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isInfoEnabled() {
+ return infoEnabled;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isQuiet() {
+ return isQuiet;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String fileName() {
+ return null;
+ }
+
+ /**
+ * Sets the gateway.
+ *
+ * @param gate Callback gateway.
+ */
+ public void setGateway(PlatformCallbackGateway gate) {
+ assert gate != null;
+ this.gate = gate;
+
+ // Pre-calculate enabled levels (JNI calls are expensive)
+ traceEnabled = gate.loggerIsLevelEnabled(LVL_TRACE);
+ debugEnabled = gate.loggerIsLevelEnabled(LVL_DEBUG);
+ infoEnabled = gate.loggerIsLevelEnabled(LVL_INFO);
+ }
+
+ /**
+ * Sets the context.
+ *
+ * @param ctx Platform context.
+ */
+ public void setContext(PlatformContext ctx) {
+ assert ctx != null;
+ this.ctx = ctx;
+ }
+
+ /**
+ * Logs the message.
+ *
+ * @param level Log level.
+ * @param msg Message.
+ * @param e Exception.
+ */
+ private void log(int level, String msg, @Nullable Throwable e) {
+ String errorInfo = null;
+
+ if (e != null)
+ errorInfo = X.getFullStackTrace(e);
+
+ PlatformNativeException e0 = X.cause(e, PlatformNativeException.class);
+ if (ctx != null && e0 != null) {
+ try (PlatformMemory mem = ctx.memory().allocate()) {
+ PlatformOutputStream out = mem.output();
+ BinaryRawWriterEx writer = ctx.writer(out);
+ writer.writeObject(e0.cause());
+ out.synchronize();
+
+ gate.loggerLog(level, msg, category, errorInfo, mem.pointer());
+ }
+ }
+ else {
+ gate.loggerLog(level, msg, category, errorInfo, 0);
+ }
+ }
+
+ /**
+ * Gets the category string.
+ *
+ * @param ctgr Category object.
+ * @return Category string.
+ */
+ private static String getCategoryString(Object ctgr) {
+ return ctgr instanceof Class
+ ? ((Class)ctgr).getName()
+ : (ctgr == null ? null : String.valueOf(ctgr));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java
index a28677f..8b4eb75 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java
@@ -22,7 +22,9 @@ import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.logger.platform.PlatformLogger;
import org.apache.ignite.internal.processors.platform.memory.PlatformExternalMemory;
+import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteClosure;
@@ -35,7 +37,11 @@ public abstract class PlatformAbstractBootstrap implements PlatformBootstrap {
/** {@inheritDoc} */
@Override public PlatformProcessor start(IgniteConfiguration cfg, @Nullable GridSpringResourceContext springCtx,
long envPtr, long dataPtr) {
- Ignition.setClientMode(new PlatformExternalMemory(null, dataPtr).input().readBoolean());
+ final PlatformInputStream input = new PlatformExternalMemory(null, dataPtr).input();
+
+ Ignition.setClientMode(input.readBoolean());
+
+ processInput(input, cfg);
IgniteConfiguration cfg0 = closure(envPtr).apply(cfg);
@@ -61,4 +67,14 @@ public abstract class PlatformAbstractBootstrap implements PlatformBootstrap {
* @return Closure.
*/
protected abstract IgniteClosure<IgniteConfiguration, IgniteConfiguration> closure(long envPtr);
+
+ /**
+ * Processes any additional input data.
+ *
+ * @param input Input stream.
+ * @param cfg Config.
+ */
+ protected void processInput(PlatformInputStream input, IgniteConfiguration cfg) {
+ // No-op.
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java
index 66eff8b..96e4643 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.processors.platform;
+import org.apache.ignite.internal.logger.platform.PlatformLogger;
import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl;
@@ -45,4 +46,9 @@ public interface PlatformConfigurationEx {
* @return Warnings to be displayed on grid start.
*/
public Collection<String> warnings();
+
+ /**
+ * @return Platform logger.
+ */
+ public PlatformLogger logger();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java
index cdf418f..a7b7a8d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java
@@ -175,4 +175,14 @@ public class PlatformNoopProcessor extends GridProcessorAdapter implements Platf
@Override public PlatformTarget getOrCreateNearCache(@Nullable String cacheName, long memPtr) {
return null;
}
+
+ /** {@inheritDoc} */
+ @Override public boolean loggerIsLevelEnabled(int level) {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void loggerLog(int level, String message, String category, String errorInfo) {
+ // No-op.
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java
index fc42b68..fdc66cb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java
@@ -259,4 +259,20 @@ public interface PlatformProcessor extends GridProcessor {
*/
public PlatformTarget getOrCreateNearCache(@Nullable String cacheName, long memPtr);
+ /**
+ * Gets a value indicating whether Ignite logger has specified level enabled.
+ *
+ * @param level Log level.
+ */
+ public boolean loggerIsLevelEnabled(int level);
+
+ /**
+ * Logs to the Ignite logger.
+ *
+ * @param level Log level.
+ * @param message Message.
+ * @param category Category.
+ * @param errorInfo Error info.
+ */
+ public void loggerLog(int level, String message, String category, String errorInfo);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
index 8c9e205..e367768 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
@@ -30,6 +30,7 @@ import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.binary.BinaryRawReaderEx;
import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.logger.platform.PlatformLogger;
import org.apache.ignite.internal.processors.GridProcessorAdapter;
import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
import org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl;
@@ -118,6 +119,9 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
}
platformCtx = new PlatformContextImpl(ctx, interopCfg.gate(), interopCfg.memory(), interopCfg.platform());
+
+ if (interopCfg.logger() != null)
+ interopCfg.logger().setContext(platformCtx);
}
/** {@inheritDoc} */
@@ -416,6 +420,58 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
return new PlatformCache(platformCtx, cache.keepBinary(), false);
}
+ /** {@inheritDoc} */
+ @Override public boolean loggerIsLevelEnabled(int level) {
+ IgniteLogger log = ctx.grid().log();
+
+ switch (level) {
+ case PlatformLogger.LVL_TRACE:
+ return log.isTraceEnabled();
+ case PlatformLogger.LVL_DEBUG:
+ return log.isDebugEnabled();
+ case PlatformLogger.LVL_INFO:
+ return log.isInfoEnabled();
+ case PlatformLogger.LVL_WARN:
+ return true;
+ case PlatformLogger.LVL_ERROR:
+ return true;
+ default:
+ assert false;
+ }
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void loggerLog(int level, String message, String category, String errorInfo) {
+ IgniteLogger log = ctx.grid().log();
+
+ if (category != null)
+ log = log.getLogger(category);
+
+ Throwable err = errorInfo == null ? null : new IgniteException("Platform error:" + errorInfo);
+
+ switch (level) {
+ case PlatformLogger.LVL_TRACE:
+ log.trace(message);
+ break;
+ case PlatformLogger.LVL_DEBUG:
+ log.debug(message);
+ break;
+ case PlatformLogger.LVL_INFO:
+ log.info(message);
+ break;
+ case PlatformLogger.LVL_WARN:
+ log.warning(message, err);
+ break;
+ case PlatformLogger.LVL_ERROR:
+ log.error(message, err);
+ break;
+ default:
+ assert false;
+ }
+ }
+
/**
* Gets the near cache config.
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java
index 41d3802..de23242 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackGateway.java
@@ -943,6 +943,44 @@ public class PlatformCallbackGateway {
}
/**
+ * Logs to the platform.
+ *
+ * @param level Log level.
+ * @param message Message.
+ * @param category Category.
+ * @param errorInfo Error info.
+ * @param memPtr Pointer to optional payload (serialized exception).
+ */
+ public void loggerLog(int level, String message, String category, String errorInfo, long memPtr) {
+ if (!tryEnter())
+ return; // Do not lock for logger: this should work during shutdown
+
+ try {
+ PlatformCallbackUtils.loggerLog(envPtr, level, message, category, errorInfo, memPtr);
+ }
+ finally {
+ leave();
+ }
+ }
+
+ /**
+ * Gets a value indicating whether native logger has specified level enabled.
+ *
+ * @param level Log level.
+ */
+ public boolean loggerIsLevelEnabled(int level) {
+ if (!tryEnter())
+ return false; // Do not lock for logger: this should work during shutdown
+
+ try {
+ return PlatformCallbackUtils.loggerIsLevelEnabled(envPtr, level);
+ }
+ finally {
+ leave();
+ }
+ }
+
+ /**
* Kernal stop callback.
*/
public void onStop() {
@@ -1058,6 +1096,13 @@ public class PlatformCallbackGateway {
}
/**
+ * Enter gateway.
+ */
+ protected boolean tryEnter() {
+ return lock.enterBusy();
+ }
+
+ /**
* Leave gateway.
*/
protected void leave() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
index 63c6682..09a7f1b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
@@ -553,6 +553,26 @@ public class PlatformCallbackUtils {
static native void consoleWrite(String str, boolean isErr);
/**
+ * Logs to the native logger.
+ *
+ * @param envPtr Environment pointer.
+ * @param level Log level.
+ * @param message Message.
+ * @param category Category.
+ * @param errorInfo Error info.
+ * @param memPtr Pointer to optional payload (serialized exception).
+ */
+ static native void loggerLog(long envPtr, int level, String message, String category, String errorInfo, long memPtr);
+
+ /**
+ * Gets a value indicating whether native logger has specified level enabled.
+ *
+ * @param envPtr Environment pointer.
+ * @param level Log level.
+ */
+ static native boolean loggerIsLevelEnabled(long envPtr, int level);
+
+ /**
* Private constructor.
*/
private PlatformCallbackUtils() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java
index ea11ce9..75c48ef 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.processors.platform.cpp;
+import org.apache.ignite.internal.logger.platform.PlatformLogger;
import org.apache.ignite.internal.processors.platform.PlatformConfigurationEx;
import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl;
@@ -73,6 +74,11 @@ public class PlatformCppConfigurationEx extends PlatformCppConfiguration impleme
return warns;
}
+ /** {@inheritDoc} */
+ @Override public PlatformLogger logger() {
+ return null;
+ }
+
/**
* @param warnings Warnings.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetBootstrap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetBootstrap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetBootstrap.java
index 9278246..84a4577 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetBootstrap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetBootstrap.java
@@ -17,8 +17,11 @@
package org.apache.ignite.internal.processors.platform.dotnet;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.logger.platform.PlatformLogger;
import org.apache.ignite.internal.processors.platform.PlatformAbstractBootstrap;
import org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurationClosure;
+import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
import java.io.PrintStream;
@@ -40,4 +43,10 @@ public class PlatformDotNetBootstrap extends PlatformAbstractBootstrap {
@Override protected PlatformAbstractConfigurationClosure closure(long envPtr) {
return new PlatformDotNetConfigurationClosure(envPtr);
}
+
+ /** {@inheritDoc} */
+ @Override protected void processInput(PlatformInputStream input, IgniteConfiguration cfg) {
+ if (input.readBoolean())
+ cfg.setGridLogger(new PlatformLogger());
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
index cb9696c..0c691af 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
@@ -31,6 +31,7 @@ import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.binary.BinaryRawWriterEx;
import org.apache.ignite.internal.binary.BinaryReaderExImpl;
import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.logger.platform.PlatformLogger;
import org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurationClosure;
import org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -89,7 +90,15 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
memMgr = new PlatformMemoryManagerImpl(gate, 1024);
- PlatformDotNetConfigurationEx dotNetCfg0 = new PlatformDotNetConfigurationEx(dotNetCfg, gate, memMgr);
+ PlatformLogger userLogger = null;
+
+ if (igniteCfg.getGridLogger() instanceof PlatformLogger) {
+ userLogger = (PlatformLogger)igniteCfg.getGridLogger();
+ userLogger.setGateway(gate);
+ }
+
+ PlatformDotNetConfigurationEx dotNetCfg0 = new PlatformDotNetConfigurationEx(dotNetCfg, gate, memMgr,
+ userLogger);
igniteCfg.setPlatformConfiguration(dotNetCfg0);
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java
index eaf0997..906080e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.processors.platform.dotnet;
+import org.apache.ignite.internal.logger.platform.PlatformLogger;
import org.apache.ignite.internal.processors.platform.PlatformConfigurationEx;
import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl;
@@ -35,6 +36,9 @@ public class PlatformDotNetConfigurationEx extends PlatformDotNetConfiguration i
/** Memory manager. */
private final PlatformMemoryManagerImpl memMgr;
+ /** Logger. */
+ private final PlatformLogger logger;
+
/** Warnings */
private Collection<String> warnings;
@@ -46,11 +50,12 @@ public class PlatformDotNetConfigurationEx extends PlatformDotNetConfiguration i
* @param memMgr Memory manager.
*/
public PlatformDotNetConfigurationEx(PlatformDotNetConfiguration cfg, PlatformCallbackGateway gate,
- PlatformMemoryManagerImpl memMgr) {
+ PlatformMemoryManagerImpl memMgr, PlatformLogger logger) {
super(cfg);
this.gate = gate;
this.memMgr = memMgr;
+ this.logger = logger;
}
/** {@inheritDoc} */
@@ -73,6 +78,11 @@ public class PlatformDotNetConfigurationEx extends PlatformDotNetConfiguration i
return warnings;
}
+ /** {@inheritDoc} */
+ @Override public PlatformLogger logger() {
+ return logger;
+ }
+
/**
* @param warnings Warnings.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/cpp/jni/include/ignite/jni/exports.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/jni/include/ignite/jni/exports.h b/modules/platforms/cpp/jni/include/ignite/jni/exports.h
index 3f400fb..7fae0d2 100644
--- a/modules/platforms/cpp/jni/include/ignite/jni/exports.h
+++ b/modules/platforms/cpp/jni/include/ignite/jni/exports.h
@@ -54,6 +54,8 @@ extern "C" {
void* IGNITE_CALL IgniteProcessorAtomicReference(gcj::JniContext* ctx, void* obj, char* name, long long memPtr, bool create);
void IGNITE_CALL IgniteProcessorGetIgniteConfiguration(gcj::JniContext* ctx, void* obj, long long memPtr);
void IGNITE_CALL IgniteProcessorGetCacheNames(gcj::JniContext* ctx, void* obj, long long memPtr);
+ bool IGNITE_CALL IgniteProcessorLoggerIsLevelEnabled(gcj::JniContext* ctx, void* obj, int level);
+ void IGNITE_CALL IgniteProcessorLoggerLog(gcj::JniContext* ctx, void* obj, int level, char* message, char* category, char* errorInfo);
long long IGNITE_CALL IgniteTargetInStreamOutLong(gcj::JniContext* ctx, void* obj, int opType, long long memPtr);
void IGNITE_CALL IgniteTargetInStreamOutStream(gcj::JniContext* ctx, void* obj, int opType, long long inMemPtr, long long outMemPtr);
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/cpp/jni/include/ignite/jni/java.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/jni/include/ignite/jni/java.h b/modules/platforms/cpp/jni/include/ignite/jni/java.h
index 8d79a7d..4cf00a3 100644
--- a/modules/platforms/cpp/jni/include/ignite/jni/java.h
+++ b/modules/platforms/cpp/jni/include/ignite/jni/java.h
@@ -108,6 +108,9 @@ namespace ignite
typedef void(JNICALL *ConsoleWriteHandler)(const char* chars, int charsLen, unsigned char isErr);
+ typedef void(JNICALL *LoggerLogHandler)(void* target, int level, const char* messageChars, int messageCharsLen, const char* categoryChars, int categoryCharsLen, const char* errorInfoChars, int errorInfoCharsLen, long long memPtr);
+ typedef bool(JNICALL *LoggerIsLevelEnabledHandler)(void* target, int level);
+
/**
* JNI handlers holder.
*/
@@ -191,6 +194,9 @@ namespace ignite
AffinityFunctionAssignPartitionsHandler affinityFunctionAssignPartitions;
AffinityFunctionRemoveNodeHandler affinityFunctionRemoveNode;
AffinityFunctionDestroyHandler affinityFunctionDestroy;
+
+ LoggerLogHandler loggerLog;
+ LoggerIsLevelEnabledHandler loggerIsLevelEnabled;
};
/**
@@ -335,6 +341,8 @@ namespace ignite
jmethodID m_PlatformProcessor_getCacheNames;
jmethodID m_PlatformProcessor_atomicSequence;
jmethodID m_PlatformProcessor_atomicReference;
+ jmethodID m_PlatformProcessor_loggerIsLevelEnabled;
+ jmethodID m_PlatformProcessor_loggerLog;
jclass c_PlatformTarget;
jmethodID m_PlatformTarget_inStreamOutLong;
@@ -554,6 +562,8 @@ namespace ignite
jobject ProcessorAtomicReference(jobject obj, char* name, long long memPtr, bool create);
void ProcessorGetIgniteConfiguration(jobject obj, long long memPtr);
void ProcessorGetCacheNames(jobject obj, long long memPtr);
+ bool ProcessorLoggerIsLevelEnabled(jobject obj, int level);
+ void ProcessorLoggerLog(jobject obj, int level, char* message, char* category, char* errorInfo);
long long TargetInStreamOutLong(jobject obj, int type, long long memPtr, JniErrorInfo* errInfo = NULL);
void TargetInStreamOutStream(jobject obj, int opType, long long inMemPtr, long long outMemPtr, JniErrorInfo* errInfo = NULL);
@@ -767,6 +777,9 @@ namespace ignite
JNIEXPORT void JNICALL JniAffinityFunctionDestroy(JNIEnv *env, jclass cls, jlong envPtr, jlong ptr);
JNIEXPORT void JNICALL JniConsoleWrite(JNIEnv *env, jclass cls, jstring str, jboolean isErr);
+
+ JNIEXPORT void JNICALL JniLoggerLog(JNIEnv *env, jclass cls, jlong envPtr, jint level, jstring message, jstring category, jstring errorInfo, jlong memPtr);
+ JNIEXPORT jboolean JNICALL JniLoggerIsLevelEnabled(JNIEnv *env, jclass cls, jlong envPtr, jint level);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/cpp/jni/project/vs/module.def
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/jni/project/vs/module.def b/modules/platforms/cpp/jni/project/vs/module.def
index ddddace..c1582e6 100644
--- a/modules/platforms/cpp/jni/project/vs/module.def
+++ b/modules/platforms/cpp/jni/project/vs/module.def
@@ -136,4 +136,5 @@ IgniteProcessorGetCacheNames @133
IgniteProjectionForServers @134
IgniteSetConsoleHandler @135
IgniteRemoveConsoleHandler @136
-
\ No newline at end of file
+IgniteProcessorLoggerIsLevelEnabled @137
+IgniteProcessorLoggerLog @138
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/cpp/jni/src/exports.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/jni/src/exports.cpp b/modules/platforms/cpp/jni/src/exports.cpp
index 2950d15..8ef8188 100644
--- a/modules/platforms/cpp/jni/src/exports.cpp
+++ b/modules/platforms/cpp/jni/src/exports.cpp
@@ -93,11 +93,11 @@ extern "C" {
void*IGNITE_CALL IgniteProcessorDataStreamer(gcj::JniContext* ctx, void* obj, char* name, bool keepPortable) {
return ctx->ProcessorDataStreamer(static_cast<jobject>(obj), name, keepPortable);
}
-
+
void* IGNITE_CALL IgniteProcessorTransactions(gcj::JniContext* ctx, void* obj) {
return ctx->ProcessorTransactions(static_cast<jobject>(obj));
}
-
+
void* IGNITE_CALL IgniteProcessorCompute(gcj::JniContext* ctx, void* obj, void* prj) {
return ctx->ProcessorCompute(static_cast<jobject>(obj), static_cast<jobject>(prj));
}
@@ -138,6 +138,14 @@ extern "C" {
return ctx->ProcessorGetCacheNames(static_cast<jobject>(obj), memPtr);
}
+ bool IGNITE_CALL IgniteProcessorLoggerIsLevelEnabled(gcj::JniContext* ctx, void* obj, int level) {
+ return ctx->ProcessorLoggerIsLevelEnabled(static_cast<jobject>(obj), level);
+ }
+
+ void IGNITE_CALL IgniteProcessorLoggerLog(gcj::JniContext* ctx, void* obj, int level, char* message, char* category, char* errorInfo) {
+ ctx->ProcessorLoggerLog(static_cast<jobject>(obj), level, message, category, errorInfo);
+ }
+
long long IGNITE_CALL IgniteTargetInStreamOutLong(gcj::JniContext* ctx, void* obj, int opType, long long memPtr) {
return ctx->TargetInStreamOutLong(static_cast<jobject>(obj), opType, memPtr);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/cpp/jni/src/java.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/jni/src/java.cpp b/modules/platforms/cpp/jni/src/java.cpp
index 7bd6287..eb0d89a 100644
--- a/modules/platforms/cpp/jni/src/java.cpp
+++ b/modules/platforms/cpp/jni/src/java.cpp
@@ -216,6 +216,8 @@ namespace ignite
JniMethod M_PLATFORM_PROCESSOR_ATOMIC_REFERENCE = JniMethod("atomicReference", "(Ljava/lang/String;JZ)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
JniMethod M_PLATFORM_PROCESSOR_GET_IGNITE_CONFIGURATION = JniMethod("getIgniteConfiguration", "(J)V", false);
JniMethod M_PLATFORM_PROCESSOR_GET_CACHE_NAMES = JniMethod("getCacheNames", "(J)V", false);
+ JniMethod M_PLATFORM_PROCESSOR_LOGGER_IS_LEVEL_ENABLED = JniMethod("loggerIsLevelEnabled", "(I)Z", false);
+ JniMethod M_PLATFORM_PROCESSOR_LOGGER_LOG = JniMethod("loggerLog", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", false);
const char* C_PLATFORM_TARGET = "org/apache/ignite/internal/processors/platform/PlatformTarget";
JniMethod M_PLATFORM_TARGET_IN_STREAM_OUT_LONG = JniMethod("inStreamOutLong", "(IJ)J", false);
@@ -366,6 +368,9 @@ namespace ignite
JniMethod M_PLATFORM_CALLBACK_UTILS_ON_CLIENT_DISCONNECTED = JniMethod("onClientDisconnected", "(J)V", true);
JniMethod M_PLATFORM_CALLBACK_UTILS_ON_CLIENT_RECONNECTED = JniMethod("onClientReconnected", "(JZ)V", true);
+ JniMethod M_PLATFORM_CALLBACK_UTILS_LOGGER_LOG = JniMethod("loggerLog", "(JILjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V", true);
+ JniMethod M_PLATFORM_CALLBACK_UTILS_LOGGER_IS_LEVEL_ENABLED = JniMethod("loggerIsLevelEnabled", "(JI)Z", true);
+
JniMethod M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_INIT = JniMethod("affinityFunctionInit", "(JJLorg/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinityFunctionTarget;)J", true);
JniMethod M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_PARTITION = JniMethod("affinityFunctionPartition", "(JJJ)I", true);
JniMethod M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_ASSIGN_PARTITIONS = JniMethod("affinityFunctionAssignPartitions", "(JJJJ)V", true);
@@ -716,6 +721,8 @@ namespace ignite
m_PlatformProcessor_atomicReference = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_ATOMIC_REFERENCE);
m_PlatformProcessor_getIgniteConfiguration = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_IGNITE_CONFIGURATION);
m_PlatformProcessor_getCacheNames = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_CACHE_NAMES);
+ m_PlatformProcessor_loggerIsLevelEnabled = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_LOGGER_IS_LEVEL_ENABLED);
+ m_PlatformProcessor_loggerLog = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_LOGGER_LOG);
c_PlatformTarget = FindClass(env, C_PLATFORM_TARGET);
m_PlatformTarget_inStreamOutLong = FindMethod(env, c_PlatformTarget, M_PLATFORM_TARGET_IN_STREAM_OUT_LONG);
@@ -851,7 +858,7 @@ namespace ignite
void RegisterNatives(JNIEnv* env) {
{
- JNINativeMethod methods[60];
+ JNINativeMethod methods[62];
int idx = 0;
@@ -935,6 +942,9 @@ namespace ignite
AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_AFFINITY_FUNCTION_DESTROY, reinterpret_cast<void*>(JniAffinityFunctionDestroy));
AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_CONSOLE_WRITE, reinterpret_cast<void*>(JniConsoleWrite));
+ AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_LOGGER_LOG, reinterpret_cast<void*>(JniLoggerLog));
+ AddNativeMethod(methods + idx++, M_PLATFORM_CALLBACK_UTILS_LOGGER_IS_LEVEL_ENABLED, reinterpret_cast<void*>(JniLoggerIsLevelEnabled));
+
jint res = env->RegisterNatives(FindClass(env, C_PLATFORM_CALLBACK_UTILS), methods, idx);
if (res != JNI_OK)
@@ -1526,6 +1536,40 @@ namespace ignite
ExceptionCheck(env);
}
+ bool JniContext::ProcessorLoggerIsLevelEnabled(jobject obj, int level)
+ {
+ JNIEnv* env = Attach();
+
+ jboolean res = env->CallBooleanMethod(obj, jvm->GetMembers().m_PlatformProcessor_loggerIsLevelEnabled, level);
+
+ ExceptionCheck(env);
+
+ return res != 0;
+ }
+
+ void JniContext::ProcessorLoggerLog(jobject obj, int level, char* message, char* category, char* errorInfo)
+ {
+ JNIEnv* env = Attach();
+
+ jstring message0 = message != NULL ? env->NewStringUTF(message) : NULL;
+ jstring category0 = category != NULL ? env->NewStringUTF(category) : NULL;
+ jstring errorInfo0 = errorInfo != NULL ? env->NewStringUTF(errorInfo) : NULL;
+
+
+ env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformProcessor_loggerLog, level, message0, category0, errorInfo0);
+
+ if (message0)
+ env->DeleteLocalRef(message0);
+
+ if (category0)
+ env->DeleteLocalRef(category0);
+
+ if (errorInfo0)
+ env->DeleteLocalRef(errorInfo0);
+
+ ExceptionCheck(env);
+ }
+
long long JniContext::TargetInStreamOutLong(jobject obj, int opType, long long memPtr, JniErrorInfo* err) {
JNIEnv* env = Attach();
@@ -2952,6 +2996,32 @@ namespace ignite
CONSOLE_LOCK.Leave();
}
+
+ JNIEXPORT void JNICALL JniLoggerLog(JNIEnv *env, jclass cls, jlong envPtr, jint level, jstring message, jstring category, jstring errorInfo, jlong memPtr) {
+ int messageLen;
+ char* messageChars = StringToChars(env, message, &messageLen);
+
+ int categoryLen;
+ char* categoryChars = StringToChars(env, category, &categoryLen);
+
+ int errorInfoLen;
+ char* errorInfoChars = StringToChars(env, errorInfo, &errorInfoLen);
+
+ IGNITE_SAFE_PROC(env, envPtr, LoggerLogHandler, loggerLog, level, messageChars, messageLen, categoryChars, categoryLen, errorInfoChars, errorInfoLen, memPtr);
+
+ if (messageChars)
+ delete[] messageChars;
+
+ if (categoryChars)
+ delete[] categoryChars;
+
+ if (errorInfoChars)
+ delete[] errorInfoChars;
+ }
+
+ JNIEXPORT jboolean JNICALL JniLoggerIsLevelEnabled(JNIEnv *env, jclass cls, jlong envPtr, jint level) {
+ IGNITE_SAFE_FUNC(env, envPtr, LoggerIsLevelEnabledHandler, loggerIsLevelEnabled, level);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index 7d21b34..29dc81b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -56,6 +56,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Log\DefaultLoggerTest.cs" />
<Compile Include="TestAppConfig.cs" />
<Compile Include="AspNet\IgniteOutputCacheProviderTest.cs" />
<Compile Include="Binary\BinaryBuilderSelfTestFullFooter.cs" />
@@ -139,6 +140,7 @@
<Compile Include="LifecycleTest.cs" />
<Compile Include="LoadDllTest.cs" />
<Compile Include="IgniteManagerTest.cs" />
+ <Compile Include="Log\CustomLoggerTest.cs" />
<Compile Include="MarshallerTest.cs" />
<Compile Include="MessagingTest.cs" />
<Compile Include="BinaryConfigurationTest.cs" />
@@ -249,6 +251,12 @@
<Content Include="Config\Lifecycle\lifecycle-no-beans.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="Config\Log\dotnet-log4j.xml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Config\Log\custom-log.xml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="Config\spring-test.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStringTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStringTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStringTest.cs
index 0c1f0f3..0593af7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStringTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStringTest.cs
@@ -18,7 +18,6 @@
namespace Apache.Ignite.Core.Tests.Binary
{
using System;
- using System.Diagnostics;
using Apache.Ignite.Core.Impl.Binary;
using NUnit.Framework;
@@ -83,29 +82,10 @@ namespace Apache.Ignite.Core.Tests.Binary
[Test]
public void TestNewMode()
{
- // Run "TestNewMode" in a separate process
- var envVar = BinaryUtils.IgniteBinaryMarshallerUseStringSerializationVer2;
+ // Run "TestOldMode" in a separate process with changed setting.
+ Environment.SetEnvironmentVariable(BinaryUtils.IgniteBinaryMarshallerUseStringSerializationVer2, "true");
- Environment.SetEnvironmentVariable(envVar, "true");
-
- var procStart = new ProcessStartInfo
- {
- FileName = GetType().Assembly.Location,
- Arguments = GetType().FullName + " TestOldMode",
- CreateNoWindow = true,
- UseShellExecute = false,
- RedirectStandardOutput = true,
- RedirectStandardError = true
- };
-
- var proc = Process.Start(procStart);
-
- Assert.IsNotNull(proc);
-
- Console.WriteLine(proc.StandardOutput.ReadToEnd());
- Console.WriteLine(proc.StandardError.ReadToEnd());
- Assert.IsTrue(proc.WaitForExit(15000));
- Assert.AreEqual(0, proc.ExitCode);
+ TestUtils.RunTestInNewProcess(GetType().FullName, "TestOldMode");
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/custom-log.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/custom-log.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/custom-log.xml
new file mode 100644
index 0000000..5d7dc65
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/custom-log.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+ <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <property name="localHost" value="127.0.0.1"/>
+ <property name="connectorConfiguration"><null/></property>
+
+ <property name="gridLogger">
+ <bean class="org.apache.ignite.logger.log4j.Log4JLogger">
+ <constructor-arg type="java.lang.String" value="config\log\dotnet-log4j.xml"/>
+ </bean>
+ </property>
+
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+ <property name="addresses">
+ <list>
+ <!-- In distributed environment, replace with actual host IP address. -->
+ <value>127.0.0.1:47500</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ <property name="socketTimeout" value="300" />
+ </bean>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/dotnet-log4j.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/dotnet-log4j.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/dotnet-log4j.xml
new file mode 100644
index 0000000..c8c62d7
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/dotnet-log4j.xml
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN"
+ "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
+<!--
+ Default log4j configuration for Ignite.
+-->
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+ <!--
+ Logs System.out messages to console.
+ -->
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <!-- Log to STDOUT. -->
+ <param name="Target" value="System.out"/>
+
+ <!-- Log from DEBUG and higher. -->
+ <param name="Threshold" value="DEBUG"/>
+
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss}][%-5p][%t][%c{1}] %m%n"/>
+ </layout>
+
+ <!-- Do not log beyond INFO level. -->
+ <filter class="org.apache.log4j.varia.LevelRangeFilter">
+ <param name="levelMin" value="DEBUG"/>
+ <param name="levelMax" value="INFO"/>
+ </filter>
+ </appender>
+
+ <!--
+ Logs all System.err messages to console.
+ -->
+ <appender name="CONSOLE_ERR" class="org.apache.log4j.ConsoleAppender">
+ <!-- Log to STDERR. -->
+ <param name="Target" value="System.err"/>
+
+ <!-- Log from WARN and higher. -->
+ <param name="Threshold" value="WARN"/>
+
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="[%d{dd-MMM-yyyy HH:mm:ss}][%-5p][%t][%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+ <!--
+ Logs all output to specified file.
+ By default, the logging goes to IGNITE_HOME/work/log folder
+
+ Note, this appender is disabled by default.
+ To enable, uncomment the section below and also FILE appender in the <root> element.
+ -->
+ <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
+ <param name="Threshold" value="DEBUG"/>
+ <param name="File" value="${IGNITE_HOME}/work/log/dotnet-logger-test.log"/>
+ <param name="Append" value="true"/>
+ <param name="MaxFileSize" value="10MB"/>
+ <param name="MaxBackupIndex" value="10"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+ <!--
+ Uncomment to enable Ignite debugging.
+ -->
+ <!--
+ <category name="org.apache.ignite">
+ <level value="DEBUG"/>
+ </category>
+ -->
+
+ <!--
+ Uncomment this category to enable cache
+ query execution tracing.
+ -->
+ <!--
+ <category name="org.apache.ignite.cache.queries">
+ <level value="DEBUG"/>
+ </category>
+ -->
+
+ <!--
+ Uncomment to enable DGC tracing.
+ -->
+ <!--
+ <category name="org.apache.ignite.grid.kernal.processors.cache.GridCacheDgcManager.trace">
+ <level value="DEBUG"/>
+ </category>
+ -->
+
+ <!--
+ Uncomment to disable courtesy notice.
+ -->
+ <!--
+ <category name="org.apache.ignite.CourtesyConfigNotice">
+ <level value="OFF"/>
+ </category>
+ -->
+
+ <category name="org.springframework">
+ <level value="WARN"/>
+ </category>
+
+ <category name="org.eclipse.jetty">
+ <level value="FATAL"/>
+ </category>
+
+ <category name="com.amazonaws">
+ <level value="WARN"/>
+ </category>
+
+ <!-- Default settings. -->
+ <root>
+ <!-- Print out all info by default. -->
+ <level value="DEBUG"/>
+
+ <!-- Append to console. -->
+ <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="CONSOLE_ERR"/>
+
+ <!-- Uncomment to enable logging to a file. -->
+ <appender-ref ref="FILE"/>
+ </root>
+</log4j:configuration>
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
index b9e0236..7ba1897 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
@@ -45,6 +45,7 @@ namespace Apache.Ignite.Core.Tests
using Apache.Ignite.Core.Events;
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Core.Lifecycle;
+ using Apache.Ignite.Core.Log;
using Apache.Ignite.Core.Tests.Binary;
using Apache.Ignite.Core.Transactions;
using NUnit.Framework;
@@ -111,6 +112,7 @@ namespace Apache.Ignite.Core.Tests
<userAttributes><pair key='myNode' value='true' /></userAttributes>
<atomicConfiguration backups='2' cacheMode='Local' atomicSequenceReserveSize='250' />
<transactionConfiguration defaultTransactionConcurrency='Optimistic' defaultTransactionIsolation='RepeatableRead' defaultTimeout='0:1:2' pessimisticTransactionLogSize='15' pessimisticTransactionLogLinger='0:0:33' />
+ <logger type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+TestLogger, Apache.Ignite.Core.Tests' />
</igniteConfig>";
var cfg = IgniteConfiguration.FromXml(xml);
@@ -194,6 +196,8 @@ namespace Apache.Ignite.Core.Tests
Assert.IsNotNull(comm);
Assert.AreEqual(33, comm.AckSendThreshold);
Assert.AreEqual(new TimeSpan(0, 1, 2), comm.IdleConnectionTimeout);
+
+ Assert.IsInstanceOf<TestLogger>(cfg.Logger);
}
/// <summary>
@@ -708,6 +712,7 @@ namespace Apache.Ignite.Core.Tests
},
IsLateAffinityAssignment = false,
SpringConfigUrl = "test",
+ Logger = new TestLogger()
};
}
@@ -845,5 +850,24 @@ namespace Apache.Ignite.Core.Tests
return null;
}
}
+
+ /// <summary>
+ /// Test logger.
+ /// </summary>
+ public class TestLogger : ILogger
+ {
+ /** <inheritdoc /> */
+ public void Log(LogLevel level, string message, object[] args, IFormatProvider formatProvider, string category,
+ string nativeErrorInfo, Exception ex)
+ {
+ throw new NotImplementedException();
+ }
+
+ /** <inheritdoc /> */
+ public bool IsEnabled(LogLevel level)
+ {
+ throw new NotImplementedException();
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs
new file mode 100644
index 0000000..73134fe
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs
@@ -0,0 +1,430 @@
+\ufeff/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Tests.Log
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.Linq;
+ using Apache.Ignite.Core.Cache.Configuration;
+ using Apache.Ignite.Core.Common;
+ using Apache.Ignite.Core.Communication.Tcp;
+ using Apache.Ignite.Core.Compute;
+ using Apache.Ignite.Core.Impl;
+ using Apache.Ignite.Core.Lifecycle;
+ using Apache.Ignite.Core.Log;
+ using Apache.Ignite.Core.Resource;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests that user-defined logger receives Ignite events.
+ /// </summary>
+ public class CustomLoggerTest
+ {
+ /** */
+ private static readonly LogLevel[] AllLevels = Enum.GetValues(typeof (LogLevel)).OfType<LogLevel>().ToArray();
+
+ /// <summary>
+ /// Test setup.
+ /// </summary>
+ [SetUp]
+ public void TestSetUp()
+ {
+ TestLogger.Entries.Clear();
+ }
+
+ /// <summary>
+ /// Tests the startup output.
+ /// </summary>
+ [Test]
+ public void TestStartupOutput()
+ {
+ var cfg = GetConfigWithLogger(true);
+ using (var ignite = Ignition.Start(cfg))
+ {
+ // Check injection
+ Assert.AreEqual(((Ignite) ignite).Proxy, ((TestLogger) cfg.Logger).Ignite);
+
+ // Check initial message
+ Assert.IsTrue(TestLogger.Entries[0].Message.StartsWith("Starting Ignite.NET"));
+
+ // Check topology message
+ Assert.IsTrue(
+ TestUtils.WaitForCondition(() =>
+ {
+ lock (TestLogger.Entries)
+ {
+ return TestLogger.Entries.Any(x => x.Message.Contains("Topology snapshot"));
+ }
+ }, 9000), "No topology snapshot");
+ }
+
+ // Test that all levels are present
+ foreach (var level in AllLevels.Where(x => x != LogLevel.Error))
+ Assert.IsTrue(TestLogger.Entries.Any(x => x.Level == level), "No messages with level " + level);
+ }
+
+
+ /// <summary>
+ /// Tests startup error in Java.
+ /// </summary>
+ [Test]
+ public void TestStartupJavaError()
+ {
+ // Invalid config
+ Assert.Throws<IgniteException>(() =>
+ Ignition.Start(new IgniteConfiguration(GetConfigWithLogger())
+ {
+ CommunicationSpi = new TcpCommunicationSpi
+ {
+ IdleConnectionTimeout = TimeSpan.MinValue
+ }
+ }));
+
+ var err = TestLogger.Entries.First(x => x.Level == LogLevel.Error);
+ Assert.IsTrue(err.NativeErrorInfo.Contains("SPI parameter failed condition check: idleConnTimeout > 0"));
+ Assert.AreEqual("org.apache.ignite.internal.IgniteKernal", err.Category);
+ Assert.IsNull(err.Exception);
+ }
+
+ /// <summary>
+ /// Tests startup error in .NET.
+ /// </summary>
+ [Test]
+ public void TestStartupDotNetError()
+ {
+ // Invalid bean
+ Assert.Throws<IgniteException>(() =>
+ Ignition.Start(new IgniteConfiguration(GetConfigWithLogger())
+ {
+ LifecycleBeans = new[] {new FailBean()}
+ }));
+
+ var err = TestLogger.Entries.First(x => x.Level == LogLevel.Error);
+ Assert.IsInstanceOf<ArithmeticException>(err.Exception);
+ }
+
+ /// <summary>
+ /// Tests that .NET exception propagates through Java to the log.
+ /// </summary>
+ [Test]
+ public void TestDotNetErrorPropagation()
+ {
+ // Start 2 nodes: PlatformNativeException does not occur in local scenario
+ using (var ignite = Ignition.Start(GetConfigWithLogger()))
+ using (Ignition.Start(new IgniteConfiguration(TestUtils.GetTestConfiguration()) {GridName = "1"}))
+ {
+ var compute = ignite.GetCluster().ForRemotes().GetCompute();
+
+ Assert.Throws<ArithmeticException>(() => compute.Call(new FailFunc()));
+
+ // Log updates may not arrive immediately
+ TestUtils.WaitForCondition(() => TestLogger.Entries.Any(x => x.Exception != null), 3000);
+
+ var errFromJava = TestLogger.Entries.Single(x => x.Exception != null);
+ Assert.AreEqual("Error in func.", ((ArithmeticException) errFromJava.Exception.InnerException).Message);
+ }
+ }
+
+ /// <summary>
+ /// Tests the <see cref="QueryEntity"/> validation.
+ /// </summary>
+ [Test]
+ public void TestQueryEntityValidation()
+ {
+ var cacheCfg = new CacheConfiguration("cache1", new QueryEntity(typeof(uint), typeof(ulong))
+ {
+ Fields = new[]
+ {
+ new QueryField("myField", typeof(ushort))
+ }
+ });
+
+ var cfg = new IgniteConfiguration(GetConfigWithLogger())
+ {
+ CacheConfiguration = new[]
+ {
+ cacheCfg
+ }
+ };
+
+ using (var ignite = Ignition.Start(cfg))
+ {
+ // Check static and dynamic cache start
+ cacheCfg.Name = "cache2";
+ ignite.CreateCache<int, string>(cacheCfg);
+
+ var warns = TestLogger.Entries.Where(x => x.Level == LogLevel.Warn && x.Args != null)
+ .Select(x => string.Format(x.Message, x.Args)).ToList();
+
+ Assert.AreEqual(6, warns.Count);
+
+ Assert.AreEqual("Validating cache configuration 'cache1', QueryEntity 'java.lang.Integer:java.lang." +
+ "Long': Type 'System.UInt32' maps to Java type 'java.lang.Integer' using unchecked " +
+ "conversion. This may cause issues in SQL queries. You can use 'System.Int32' " +
+ "instead to achieve direct mapping.", warns[0]);
+
+ Assert.AreEqual("Validating cache configuration 'cache1', QueryEntity 'java.lang.Integer:java.lang." +
+ "Long': Type 'System.UInt64' maps to Java type 'java.lang.Long' using unchecked " +
+ "conversion. This may cause issues in SQL queries. You can use 'System.Int64' " +
+ "instead to achieve direct mapping.", warns[1]);
+
+ Assert.AreEqual("Validating cache configuration 'cache1', QueryEntity 'java.lang.Integer:java.lang." +
+ "Long', QueryField 'myField': Type 'System.UInt16' maps to Java type 'java.lang." +
+ "Short' using unchecked conversion. This may cause issues in SQL queries. You " +
+ "can use 'System.Int16' instead to achieve direct mapping.", warns[2]);
+
+ Assert.AreEqual("Validating cache configuration 'cache2', QueryEntity 'java.lang.Integer:java.lang." +
+ "Long': Type 'System.UInt32' maps to Java type 'java.lang.Integer' using unchecked " +
+ "conversion. This may cause issues in SQL queries. You can use 'System.Int32' " +
+ "instead to achieve direct mapping.", warns[3]);
+
+ Assert.AreEqual("Validating cache configuration 'cache2', QueryEntity 'java.lang.Integer:java.lang." +
+ "Long': Type 'System.UInt64' maps to Java type 'java.lang.Long' using unchecked " +
+ "conversion. This may cause issues in SQL queries. You can use 'System.Int64' " +
+ "instead to achieve direct mapping.", warns[4]);
+
+ Assert.AreEqual("Validating cache configuration 'cache2', QueryEntity 'java.lang.Integer:java.lang." +
+ "Long', QueryField 'myField': Type 'System.UInt16' maps to Java type 'java.lang." +
+ "Short' using unchecked conversion. This may cause issues in SQL queries. You " +
+ "can use 'System.Int16' instead to achieve direct mapping.", warns[5]);
+ }
+ }
+
+ /// <summary>
+ /// Tests the <see cref="LoggerExtensions"/> methods.
+ /// </summary>
+ [Test]
+ public void TestExtensions()
+ {
+ var log = new TestLogger(LogLevel.Trace);
+ var ex = new FieldAccessException("abc");
+
+ // Log
+ log.Log(LogLevel.Trace, "trace");
+ CheckLastMessage(LogLevel.Trace, "trace");
+
+ log.Log(LogLevel.Debug, "msg {0} {1}", 1, "2");
+ CheckLastMessage(LogLevel.Debug, "msg {0} {1}", new object[] { 1, "2" }, CultureInfo.InvariantCulture);
+
+ log.Log(LogLevel.Info, ex, "msg");
+ CheckLastMessage(LogLevel.Info, "msg", e: ex);
+
+ log.Log(LogLevel.Warn, ex, "msg {0}", 1);
+ CheckLastMessage(LogLevel.Warn, "msg {0}", new object[] {1}, CultureInfo.InvariantCulture, e: ex);
+
+ // Trace
+ log.Trace("trace");
+ CheckLastMessage(LogLevel.Trace, "trace");
+
+ log.Trace("msg {0} {1}", 1, "2");
+ CheckLastMessage(LogLevel.Trace, "msg {0} {1}", new object[] { 1, "2" }, CultureInfo.InvariantCulture);
+
+ log.Trace(ex, "msg");
+ CheckLastMessage(LogLevel.Trace, "msg", e: ex);
+
+ log.Trace(ex, "msg {0}", 1);
+ CheckLastMessage(LogLevel.Trace, "msg {0}", new object[] { 1 }, CultureInfo.InvariantCulture, e: ex);
+
+ // Debug
+ log.Debug("test");
+ CheckLastMessage(LogLevel.Debug, "test");
+
+ log.Debug("msg {0} {1}", 1, "2");
+ CheckLastMessage(LogLevel.Debug, "msg {0} {1}", new object[] { 1, "2" }, CultureInfo.InvariantCulture);
+
+ log.Debug(ex, "msg");
+ CheckLastMessage(LogLevel.Debug, "msg", e: ex);
+
+ log.Debug(ex, "msg {0}", 1);
+ CheckLastMessage(LogLevel.Debug, "msg {0}", new object[] { 1 }, CultureInfo.InvariantCulture, e: ex);
+
+ // Info
+ log.Info("test");
+ CheckLastMessage(LogLevel.Info, "test");
+
+ log.Info("msg {0} {1}", 1, "2");
+ CheckLastMessage(LogLevel.Info, "msg {0} {1}", new object[] { 1, "2" }, CultureInfo.InvariantCulture);
+
+ log.Info(ex, "msg");
+ CheckLastMessage(LogLevel.Info, "msg", e: ex);
+
+ log.Info(ex, "msg {0}", 1);
+ CheckLastMessage(LogLevel.Info, "msg {0}", new object[] { 1 }, CultureInfo.InvariantCulture, e: ex);
+
+ // Warn
+ log.Warn("test");
+ CheckLastMessage(LogLevel.Warn, "test");
+
+ log.Warn("msg {0} {1}", 1, "2");
+ CheckLastMessage(LogLevel.Warn, "msg {0} {1}", new object[] { 1, "2" }, CultureInfo.InvariantCulture);
+
+ log.Warn(ex, "msg");
+ CheckLastMessage(LogLevel.Warn, "msg", e: ex);
+
+ log.Warn(ex, "msg {0}", 1);
+ CheckLastMessage(LogLevel.Warn, "msg {0}", new object[] { 1 }, CultureInfo.InvariantCulture, e: ex);
+
+ // Error
+ log.Error("test");
+ CheckLastMessage(LogLevel.Error, "test");
+
+ log.Error("msg {0} {1}", 1, "2");
+ CheckLastMessage(LogLevel.Error, "msg {0} {1}", new object[] { 1, "2" }, CultureInfo.InvariantCulture);
+
+ log.Error(ex, "msg");
+ CheckLastMessage(LogLevel.Error, "msg", e: ex);
+
+ log.Error(ex, "msg {0}", 1);
+ CheckLastMessage(LogLevel.Error, "msg {0}", new object[] { 1 }, CultureInfo.InvariantCulture, e: ex);
+
+ // GetLogger
+ var catLog = log.GetLogger("myCategory");
+ catLog.Info("info");
+ CheckLastMessage(LogLevel.Info, "info", category: "myCategory");
+
+ catLog.Log(LogLevel.Info, "info", null, null, "explicitCat", null, null);
+ CheckLastMessage(LogLevel.Info, "info", category: "explicitCat");
+
+ catLog = catLog.GetLogger("newCat");
+ catLog.Info("info");
+ CheckLastMessage(LogLevel.Info, "info", category: "newCat");
+
+ catLog.Log(LogLevel.Info, "info", null, null, "explicitCat", null, null);
+ CheckLastMessage(LogLevel.Info, "info", category: "explicitCat");
+ }
+
+ /// <summary>
+ /// Checks the last message.
+ /// </summary>
+ private static void CheckLastMessage(LogLevel level, string message, object[] args = null,
+ IFormatProvider formatProvider = null, string category = null, string nativeErr = null, Exception e = null)
+ {
+ var msg = TestLogger.Entries.Last();
+
+ Assert.AreEqual(msg.Level, level);
+ Assert.AreEqual(msg.Message, message);
+ Assert.AreEqual(msg.Args, args);
+ Assert.AreEqual(msg.FormatProvider, formatProvider);
+ Assert.AreEqual(msg.Category, category);
+ Assert.AreEqual(msg.NativeErrorInfo, nativeErr);
+ Assert.AreEqual(msg.Exception, e);
+ }
+
+ /// <summary>
+ /// Gets the configuration with logger.
+ /// </summary>
+ private static IgniteConfiguration GetConfigWithLogger(bool verbose = false)
+ {
+ return new IgniteConfiguration(TestUtils.GetTestConfiguration())
+ {
+ Logger = new TestLogger(verbose ? LogLevel.Trace : LogLevel.Info)
+ };
+ }
+
+ /// <summary>
+ /// Test log entry.
+ /// </summary>
+ private class LogEntry
+ {
+ public LogLevel Level;
+ public string Message;
+ public object[] Args;
+ public IFormatProvider FormatProvider;
+ public string Category;
+ public string NativeErrorInfo;
+ public Exception Exception;
+
+ public override string ToString()
+ {
+ return string.Format("Level: {0}, Message: {1}, Args: {2}, FormatProvider: {3}, Category: {4}, " +
+ "NativeErrorInfo: {5}, Exception: {6}", Level, Message, Args, FormatProvider,
+ Category, NativeErrorInfo, Exception);
+ }
+ }
+
+ /// <summary>
+ /// Test logger.
+ /// </summary>
+ private class TestLogger : ILogger
+ {
+ public static readonly List<LogEntry> Entries = new List<LogEntry>(5000);
+
+ private readonly LogLevel _minLevel;
+
+ public TestLogger(LogLevel minLevel)
+ {
+ _minLevel = minLevel;
+ }
+
+ public void Log(LogLevel level, string message, object[] args, IFormatProvider formatProvider,
+ string category, string nativeErrorInfo, Exception ex)
+ {
+ if (!IsEnabled(level))
+ return;
+
+ lock (Entries)
+ {
+ Entries.Add(new LogEntry
+ {
+ Level = level,
+ Message = message,
+ Args = args,
+ FormatProvider = formatProvider,
+ Category = category,
+ NativeErrorInfo = nativeErrorInfo,
+ Exception = ex
+ });
+ }
+ }
+
+ public bool IsEnabled(LogLevel level)
+ {
+ return level >= _minLevel;
+ }
+
+ [InstanceResource]
+ // ReSharper disable once UnusedAutoPropertyAccessor.Local
+ public IIgnite Ignite { get; set; }
+ }
+
+
+ /// <summary>
+ /// Failing lifecycle bean.
+ /// </summary>
+ private class FailBean : ILifecycleBean
+ {
+ public void OnLifecycleEvent(LifecycleEventType evt)
+ {
+ throw new ArithmeticException("Failure in bean");
+ }
+ }
+
+ /// <summary>
+ /// Failing computation.
+ /// </summary>
+ [Serializable]
+ private class FailFunc : IComputeFunc<string>
+ {
+ public string Invoke()
+ {
+ throw new ArithmeticException("Error in func.");
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/DefaultLoggerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/DefaultLoggerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/DefaultLoggerTest.cs
new file mode 100644
index 0000000..6623416
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/DefaultLoggerTest.cs
@@ -0,0 +1,114 @@
+\ufeff/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Tests.Log
+{
+ using System;
+ using System.IO;
+ using System.Linq;
+ using Apache.Ignite.Core.Cache.Configuration;
+ using Apache.Ignite.Core.Impl.Common;
+ using NUnit.Framework;
+ using LogLevel = Apache.Ignite.Core.Log.LogLevel;
+
+ /// <summary>
+ /// Tests the default logger.
+ /// </summary>
+ public class DefaultLoggerTest
+ {
+ /// <summary>
+ /// Tests that default Java mechanism is used when there is no custom logger.
+ /// </summary>
+ [Test]
+ public void TestJavaLogger()
+ {
+ // Run the test in a separate process because log4jlogger has some static state,
+ // and after Ignite has been started once, it is not possible to start a new node
+ // with a different logger config.
+ const string envVar = "DefaultLoggerTest.TestJavaLogger";
+
+ if (Environment.GetEnvironmentVariable(envVar) == "true")
+ {
+ // Delete all log files from the work dir
+ Func<string[]> getLogs = () =>
+ Directory.GetFiles(IgniteHome.Resolve(null), "dotnet-logger-test.log", SearchOption.AllDirectories);
+
+ getLogs().ToList().ForEach(File.Delete);
+
+ var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration(false))
+ {
+ SpringConfigUrl = @"config\log\custom-log.xml",
+ CacheConfiguration = new[]
+ {
+ new CacheConfiguration("cache1", new QueryEntity(typeof(uint), typeof(ulong)))
+ }
+ };
+
+ // Start Ignite and verify file log
+ using (var ignite = Ignition.Start(cfg))
+ {
+ // Log with all levels
+ var log = ignite.Logger;
+ var levels = new[] {LogLevel.Trace, LogLevel.Info, LogLevel.Debug, LogLevel.Warn, LogLevel.Error};
+
+ foreach (var level in levels)
+ {
+ var ex = new Exception("EXCEPTION_TEST_" + level);
+
+ log.Log(level, "DOTNET-" + level, null, null, "=DOTNET=", null, ex);
+ }
+ }
+
+ using (var fs = File.Open(getLogs().Single(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+ {
+ var log = new StreamReader(fs).ReadToEnd();
+
+ // Check output from Java:
+ Assert.IsTrue(log.Contains(">>> Topology snapshot."));
+
+ // Check output from .NET:
+ Assert.IsTrue(log.Contains("Starting Ignite.NET " + typeof(Ignition).Assembly.GetName().Version));
+
+ Assert.IsTrue(log.Contains(
+ "Validating cache configuration 'cache1', QueryEntity 'java.lang.Integer:java.lang." +
+ "Long': Type 'System.UInt32' maps to Java type 'java.lang.Integer' using unchecked " +
+ "conversion. This may cause issues in SQL queries. You can use 'System.Int32' " +
+ "instead to achieve direct mapping."));
+
+
+ // Check custom log output (trace is disabled, errors are logged from Warn and up):
+ Assert.IsTrue(log.Contains("[INFO ][main][=DOTNET=] DOTNET-Info"));
+
+ Assert.IsTrue(log.Contains("[DEBUG][main][=DOTNET=] DOTNET-Debug"));
+
+ Assert.IsTrue(log.Contains("[WARN ][main][=DOTNET=] DOTNET-Warn"));
+ Assert.IsTrue(log.Contains("class org.apache.ignite.IgniteException: " +
+ "Platform error:System.Exception: EXCEPTION_TEST_Warn"));
+
+ Assert.IsTrue(log.Contains("[ERROR][main][=DOTNET=] DOTNET-Error"));
+ Assert.IsTrue(log.Contains("class org.apache.ignite.IgniteException: " +
+ "Platform error:System.Exception: EXCEPTION_TEST_Error"));
+ }
+ }
+ else
+ {
+ Environment.SetEnvironmentVariable(envVar, "true");
+ TestUtils.RunTestInNewProcess(GetType().FullName, "TestJavaLogger");
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
index c0b8599..d3851db 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
@@ -21,9 +21,9 @@ namespace Apache.Ignite.Core.Tests
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
+ using System.Diagnostics;
using System.Linq;
using System.Threading;
- using Apache.Ignite.Core.Discovery;
using Apache.Ignite.Core.Discovery.Tcp;
using Apache.Ignite.Core.Discovery.Tcp.Static;
using Apache.Ignite.Core.Impl;
@@ -337,5 +337,30 @@ namespace Apache.Ignite.Core.Tests
JvmClasspath = CreateTestClasspath()
};
}
+
+ /// <summary>
+ /// Runs the test in new process.
+ /// </summary>
+ public static void RunTestInNewProcess(string fixtureName, string testName)
+ {
+ var procStart = new ProcessStartInfo
+ {
+ FileName = typeof(TestUtils).Assembly.Location,
+ Arguments = fixtureName + " " + testName,
+ CreateNoWindow = true,
+ UseShellExecute = false,
+ RedirectStandardOutput = true,
+ RedirectStandardError = true
+ };
+
+ var proc = System.Diagnostics.Process.Start(procStart);
+
+ Assert.IsNotNull(proc);
+
+ Console.WriteLine(proc.StandardOutput.ReadToEnd());
+ Console.WriteLine(proc.StandardError.ReadToEnd());
+ Assert.IsTrue(proc.WaitForExit(15000));
+ Assert.AreEqual(0, proc.ExitCode);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/165c0cf9/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index 59bf090..db2a96b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -308,7 +308,6 @@
<Compile Include="Impl\Common\IgniteConfigurationXmlSerializer.cs" />
<Compile Include="Impl\Common\IgniteHome.cs" />
<Compile Include="Impl\Common\LoadedAssembliesResolver.cs" />
- <Compile Include="Impl\Common\Logger.cs" />
<Compile Include="Impl\Common\ResizeableArray.cs" />
<Compile Include="Impl\Common\TypeCaster.cs" />
<Compile Include="Impl\Common\TypeStringConverter.cs" />
@@ -343,6 +342,7 @@
<Compile Include="Impl\Ignite.cs" />
<Compile Include="Impl\IgniteManager.cs" />
<Compile Include="Impl\IgniteProxy.cs" />
+ <Compile Include="Impl\Log\JavaLogger.cs" />
<Compile Include="Impl\PlatformTarget.cs" />
<Compile Include="Impl\IgniteUtils.cs" />
<Compile Include="Impl\Handle\Handle.cs" />
@@ -435,6 +435,10 @@
<Compile Include="Interop\Package-Info.cs" />
<Compile Include="Lifecycle\ClientReconnectEventArgs.cs" />
<Compile Include="Lifecycle\Package-Info.cs" />
+ <Compile Include="Log\CategoryLogger.cs" />
+ <Compile Include="Log\ILogger.cs" />
+ <Compile Include="Log\LoggerExtensions.cs" />
+ <Compile Include="Log\LogLevel.cs" />
<Compile Include="Messaging\Package-Info.cs" />
<Compile Include="Package-Info.cs" />
<Compile Include="Lifecycle\ILifecycleBean.cs" />
[3/3] ignite git commit: Merge remote-tracking branch 'origin/master'
Posted by vo...@apache.org.
Merge remote-tracking branch 'origin/master'
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b911ff8e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b911ff8e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b911ff8e
Branch: refs/heads/master
Commit: b911ff8eb6bc43d6e309758752f56c0147cae659
Parents: 165c0cf bfa375b
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Aug 15 16:41:43 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Aug 15 16:41:43 2016 +0300
----------------------------------------------------------------------
.../internal/jdbc2/JdbcResultSetSelfTest.java | 4 +-
.../ignite/jdbc/JdbcResultSetSelfTest.java | 4 +-
.../handlers/query/QueryCommandHandler.java | 16 +-
.../rest/request/RestQueryRequest.java | 2 +-
.../query/GridQueryCommandHandlerTest.java | 191 +++++++++++++++++++
.../testsuites/IgniteRestHandlerTestSuite.java | 2 +
.../h2/GridIndexingSpiAbstractSelfTest.java | 2 +-
7 files changed, 212 insertions(+), 9 deletions(-)
----------------------------------------------------------------------