Skip to content

Commit a2bff0c

Browse files
Update Diffusion Examples to 6.7.0
1 parent a18b289 commit a2bff0c

File tree

113 files changed

+4715
-906
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+4715
-906
lines changed

apple/Features/ClientControl/ClientControlCloseSessionExample.m renamed to apple/Features/ClientControl/CloseSessionExample.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
22
//
3-
// Copyright (C) 2020 Push Technology Ltd.
3+
// Copyright (C) 2020, 2021 Push Technology Ltd.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#import "ClientControlCloseSessionExample.h"
16+
#import "CloseSessionExample.h"
1717

1818
@import Diffusion;
1919

20-
@implementation ClientControlCloseSessionExample {
20+
@implementation CloseSessionExample {
2121
PTDiffusionSession* _normalSession;
2222
PTDiffusionSession* _controlSession;
2323
NSError *_error;

apple/Features/ClientControl/ClientControlCloseSessionFilterExample.m renamed to apple/Features/ClientControl/CloseSessionFilterExample.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
22
//
3-
// Copyright (C) 2020 Push Technology Ltd.
3+
// Copyright (C) 2020, 2021 Push Technology Ltd.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#import "ClientControlCloseSessionFilterExample.h"
16+
#import "CloseSessionFilterExample.h"
1717

1818
@import Diffusion;
1919

20-
@implementation ClientControlCloseSessionFilterExample {
20+
@implementation CloseSessionFilterExample {
2121
PTDiffusionSession* _normalSession1;
2222
PTDiffusionSession* _normalSession2;
2323
PTDiffusionSession* _controlSession;

apple/Features/ClientControl/ClientControlGetSessionPropertiesExample.m renamed to apple/Features/ClientControl/GetSessionPropertiesExample.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
22
//
3-
// Copyright (C) 2020 Push Technology Ltd.
3+
// Copyright (C) 2020, 2021 Push Technology Ltd.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#import "ClientControlGetSessionPropertiesExample.h"
16+
#import "GetSessionPropertiesExample.h"
1717

1818
@import Diffusion;
1919

20-
@implementation ClientControlGetSessionPropertiesExample {
20+
@implementation GetSessionPropertiesExample {
2121
PTDiffusionSession* _normalSession;
2222
PTDiffusionSession* _controlSession;
2323
NSError *_error;

apple/Features/ClientControl/ClientControlSessionPropertiesListenerExample.m renamed to apple/Features/ClientControl/SessionPropertiesListenerExample.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
22
//
3-
// Copyright (C) 2020 Push Technology Ltd.
3+
// Copyright (C) 2020, 2021 Push Technology Ltd.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -13,14 +13,14 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#import "ClientControlSessionPropertiesListenerExample.h"
16+
#import "SessionPropertiesListenerExample.h"
1717

1818
@import Diffusion;
1919

20-
@interface ClientControlSessionPropertiesListenerExample (PTDiffusionSessionPropertiesDelegate) <PTDiffusionSessionPropertiesDelegate>
20+
@interface SessionPropertiesListenerExample (PTDiffusionSessionPropertiesDelegate) <PTDiffusionSessionPropertiesDelegate>
2121
@end
2222

23-
@implementation ClientControlSessionPropertiesListenerExample {
23+
@implementation SessionPropertiesListenerExample {
2424
PTDiffusionSession* _normalSession1;
2525
PTDiffusionSession* _normalSession2;
2626
PTDiffusionSession* _controlSession;

apple/Features/ClientControl/ClientControlSetQueueConflationExample.m renamed to apple/Features/ClientControl/SetQueueConflationExample.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
22
//
3-
// Copyright (C) 2020 Push Technology Ltd.
3+
// Copyright (C) 2020, 2021 Push Technology Ltd.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#import "ClientControlSetQueueConflationExample.h"
16+
#import "SetQueueConflationExample.h"
1717

1818
@import Diffusion;
1919

20-
@implementation ClientControlSetQueueConflationExample {
20+
@implementation SetQueueConflationExample {
2121
PTDiffusionSession* _normalSession;
2222
PTDiffusionSession* _controlSession;
2323
NSError *_error;

apple/Features/ClientControl/ClientControlSetQueueConflationFilterExample.m renamed to apple/Features/ClientControl/SetQueueConflationFilterExample.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
22
//
3-
// Copyright (C) 2020 Push Technology Ltd.
3+
// Copyright (C) 2020, 2021 Push Technology Ltd.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#import "ClientControlSetQueueConflationFilterExample.h"
16+
#import "SetQueueConflationFilterExample.h"
1717

1818
@import Diffusion;
1919

20-
@implementation ClientControlSetQueueConflationFilterExample {
20+
@implementation SetQueueConflationFilterExample {
2121
PTDiffusionSession* _normalSession1;
2222
PTDiffusionSession* _normalSession2;
2323
PTDiffusionSession* _controlSession;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
2+
//
3+
// Copyright (C) 2021 Push Technology Ltd.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#import "SetQueueEventHandlerExample.h"
17+
#import "QueueEventListener.h"
18+
19+
@import Diffusion;
20+
21+
@implementation SetQueueEventHandlerExample {
22+
PTDiffusionSession *_normalSession;
23+
PTDiffusionSession *_controlSession;
24+
QueueEventListener *_listener;
25+
PTDiffusionRegistration *_registration;
26+
NSError *_error;
27+
}
28+
29+
-(void)startWithURL:(NSURL*)url {
30+
31+
/*
32+
* We'll run this example in a another thread other than main.
33+
* This allows to run operations in a synchronous way which is easier to read.
34+
*/
35+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
36+
37+
PTDiffusionMutableSessionConfiguration *smallQueueSessionConfiguration = [[PTDiffusionMutableSessionConfiguration alloc] init];
38+
smallQueueSessionConfiguration.principal = @"client";
39+
smallQueueSessionConfiguration.credentials = [[PTDiffusionCredentials alloc] initWithPassword:@"password"];
40+
41+
// Creating normal session
42+
self->_normalSession = [self synchronousOpenSessionWithURL:url
43+
andConfiguration:smallQueueSessionConfiguration];
44+
if (!self->_normalSession) {
45+
NSLog(@"Failed to open normal session: [%@]", self->_error);
46+
return;
47+
}
48+
NSLog(@"Created normal session [%@]", self->_normalSession.sessionId);
49+
50+
51+
// Creating control session
52+
PTDiffusionMutableSessionConfiguration *controlSessionConfiguration = [[PTDiffusionMutableSessionConfiguration alloc] init];
53+
controlSessionConfiguration.principal = @"control";
54+
controlSessionConfiguration.credentials = [[PTDiffusionCredentials alloc] initWithPassword:@"password"];
55+
56+
self->_controlSession = [self synchronousOpenSessionWithURL:url
57+
andConfiguration:controlSessionConfiguration];
58+
if (!self->_controlSession) {
59+
NSLog(@"Failed to open control session: [%@]", self->_error);
60+
return;
61+
}
62+
NSLog(@"Created control session [%@]", self->_controlSession.sessionId);
63+
64+
// set QueueEventListener
65+
self->_listener = [[QueueEventListener alloc] init];
66+
[self->_controlSession.clientControl setQueueEventHandler:self->_listener
67+
completionHandler:^(PTDiffusionRegistration * _Nonnull registration, NSError * _Nullable error)
68+
{
69+
if (registration == nil) {
70+
NSLog(@"An error occurred while registering the QueueEventListener: %@", error.description);
71+
return;
72+
}
73+
74+
self->_registration = registration;
75+
NSLog(@"QueueEventListener successfully registered!");
76+
}];
77+
78+
});
79+
}
80+
81+
82+
-(PTDiffusionSession *)synchronousOpenSessionWithURL:(NSURL *)url
83+
andConfiguration:(PTDiffusionSessionConfiguration *)configuration {
84+
85+
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
86+
87+
__block PTDiffusionSession *newSession;
88+
[PTDiffusionSession openWithURL:url
89+
configuration:configuration
90+
completionHandler:^(PTDiffusionSession * _Nullable session, NSError * _Nullable error)
91+
{
92+
newSession = session;
93+
self->_error = error;
94+
dispatch_semaphore_signal(sema);
95+
}];
96+
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
97+
return newSession;
98+
}
99+
100+
@end

apple/Features/ClientControl/ClientControlSetSessionPropertiesExample.m renamed to apple/Features/ClientControl/SetSessionPropertiesExample.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
22
//
3-
// Copyright (C) 2020 Push Technology Ltd.
3+
// Copyright (C) 2020, 2021 Push Technology Ltd.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#import "ClientControlSetSessionPropertiesExample.h"
16+
#import "SetSessionPropertiesExample.h"
1717

1818
@import Diffusion;
1919

20-
@implementation ClientControlSetSessionPropertiesExample {
20+
@implementation SetSessionPropertiesExample {
2121
PTDiffusionSession* _normalSession;
2222
PTDiffusionSession* _controlSession;
2323
NSError *_error;

apple/Features/ClientControl/ClientControlSetSessionPropertiesFilterExample.m renamed to apple/Features/ClientControl/SetSessionPropertiesFilterExample.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
22
//
3-
// Copyright (C) 2020 Push Technology Ltd.
3+
// Copyright (C) 2020, 2021 Push Technology Ltd.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#import "ClientControlSetSessionPropertiesFilterExample.h"
16+
#import "SetSessionPropertiesFilterExample.h"
1717

1818
@import Diffusion;
1919

20-
@implementation ClientControlSetSessionPropertiesFilterExample {
20+
@implementation SetSessionPropertiesFilterExample {
2121
PTDiffusionSession* _normalSession1;
2222
PTDiffusionSession* _normalSession2;
2323
PTDiffusionSession* _controlSession;
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
2+
//
3+
// Copyright (C) 2021 Push Technology Ltd.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#import "SessionMetricCollectorExample.h"
17+
18+
@import Diffusion;
19+
20+
@implementation SessionMetricCollectorExample {
21+
PTDiffusionSession* _session;
22+
}
23+
24+
-(void)startWithURL:(NSURL*)url {
25+
26+
PTDiffusionCredentials *const credentials =
27+
[[PTDiffusionCredentials alloc] initWithPassword:@"password"];
28+
29+
PTDiffusionSessionConfiguration *const sessionConfiguration =
30+
[[PTDiffusionSessionConfiguration alloc] initWithPrincipal:@"admin"
31+
credentials:credentials];
32+
33+
NSLog(@"Connecting...");
34+
35+
[PTDiffusionSession openWithURL:url
36+
configuration:sessionConfiguration
37+
completionHandler:^(PTDiffusionSession *const session, NSError *const error)
38+
{
39+
if (!session) {
40+
NSLog(@"Failed to open session: %@", error);
41+
return;
42+
}
43+
44+
// At this point we now have a connected session.
45+
NSLog(@"Connected.");
46+
47+
// Set ivar to maintain a strong reference to the session.
48+
self->_session = session;
49+
50+
// create a session metric collector using its builder
51+
PTDiffusionSessionMetricCollector *const collector =
52+
[[[[[PTDiffusionSessionMetricCollectorBuilder new]
53+
exportToPrometheus:YES]
54+
removeMetricsWithNoMatches:NO]
55+
groupByProperty:@"$Location"]
56+
createCollectorWithName:@"collector 1" andSessionFilter:@"$Principal is 'control'"];
57+
58+
PTDiffusionMetricsFeature *const metrics = session.metrics;
59+
60+
// place the session metric collector in the server
61+
[metrics putSessionMetricCollector:collector
62+
completionHandler:^(NSError * _Nullable error)
63+
{
64+
if (error != nil) {
65+
NSLog(@"An error has occurred while setting the collector: %@", error);
66+
return;
67+
}
68+
69+
NSLog(@"Listing available session metric collectors");
70+
71+
// list all session metric collectors in the server
72+
[metrics listSessionMetricCollectors:^(NSArray<PTDiffusionSessionMetricCollector *> * _Nullable collectors,
73+
NSError * _Nullable error)
74+
{
75+
if (error != nil) {
76+
NSLog(@"An error has occurred while listing the available session metric collectors: %@", error);
77+
return;
78+
}
79+
80+
for (PTDiffusionSessionMetricCollector *c in collectors) {
81+
NSLog(@"%@", c.name);
82+
NSLog(@"\tSession Filter: %@", c.sessionFilter);
83+
NSLog(@"\tExports to Prometheus: %@", c.exportsToPrometheus ? @"YES" : @"NO");
84+
NSLog(@"\tRemoves metrics with no matches: %@", c.removesMetricsWithNoMatches ? @"YES" : @"NO");
85+
NSLog(@"\tGroup by properties:");
86+
for (NSString *property in c.groupByProperties) {
87+
NSLog(@"\t\t%@", property);
88+
}
89+
}
90+
91+
NSLog(@"Removing collector");
92+
93+
// remove the session metric collector we created
94+
[metrics removeSessionMetricCollector:@"collector 1"
95+
completionHandler:^(NSError * _Nullable error)
96+
{
97+
if (error != nil) {
98+
NSLog(@"An error has occurred while removing the session metric collector: %@", error);
99+
return;
100+
}
101+
102+
NSLog(@"Done.");
103+
}];
104+
}];
105+
106+
}];
107+
}];
108+
}
109+
110+
111+
@end

0 commit comments

Comments
 (0)