Statistics
| Branch: | Tag: | Revision:

root / Classes / LoadBalancerConnectionThrottle.m @ 72744ed1

History | View | Annotate | Download (1.8 kB)

1
//
2
//  LoadBalancerConnectionThrottle.m
3
//  OpenStack
4
//
5
//  Created by Mike Mayo on 7/11/11.
6
//  Copyright 2011 __MyCompanyName__. All rights reserved.
7
//
8

    
9
#import "LoadBalancerConnectionThrottle.h"
10
#import "NSObject+NSCoding.h"
11
#import "NSString+Conveniences.h"
12

    
13

    
14
@implementation LoadBalancerConnectionThrottle
15

    
16
@synthesize minConnections, maxConnections, maxConnectionRate, rateInterval;
17

    
18
#pragma mark - Serialization
19

    
20
- (void)encodeWithCoder: (NSCoder *)coder {
21
    [self autoEncodeWithCoder:coder];    
22
}
23

    
24
- (id)initWithCoder:(NSCoder *)coder {
25
    if ((self = [super init])) {
26
        [self autoDecode:coder];
27
    }
28
    return self;
29
}
30

    
31
#pragma mark - JSON
32

    
33
+ (LoadBalancerConnectionThrottle *)fromJSON:(NSDictionary *)dict {
34
    LoadBalancerConnectionThrottle *t = [[[LoadBalancerConnectionThrottle alloc] init] autorelease];
35
    t.minConnections = [[dict objectForKey:@"minConnections"] intValue];
36
    t.maxConnections = [[dict objectForKey:@"maxConnections"] intValue];
37
    t.maxConnectionRate = [[dict objectForKey:@"maxConnectionRate"] intValue];
38
    t.rateInterval = [[dict objectForKey:@"rateInterval"] intValue];
39
    return t;
40
}
41

    
42
- (NSString *)toJSON {
43
    NSString *json
44
        = @"{ \"connectionThrottle\": { "
45
        "        \"minConnections\": \"<minConnections>\","
46
        "        \"maxConnections\": \"<maxConnections>\","
47
        "        \"maxConnectionRate\": \"<maxConnectionRate>\","
48
        "        \"rateInterval\": \"<rateInterval>\""
49
        "  }}";
50
    json = [json replace:@"<minConnections>" withInt:self.minConnections];
51
    json = [json replace:@"<maxConnections>" withInt:self.maxConnections];
52
    json = [json replace:@"<maxConnectionRate>" withInt:self.maxConnectionRate];
53
    json = [json replace:@"<rateInterval>" withInt:self.rateInterval];
54
    return json;
55
}
56

    
57
@end